Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Стандартнабібліотека класів c#
Зміст1.    Що таке Generic? Extension methods.2.    Math3.    DateTime, TimeSpan4.    Regex5.    Колекції. System.Collecti...
Generics    • Generic methods:       • FirstOrDefault<T>(T[] array)       • FirstOrDefault<T>(T[] array, T defaultValue)  ...
Extension methods                               Simply static methods                                  Used for convenienc...
Math       • Math.Abs(number)       • Math.Pow(number)       • Math.Sin(angle)       • Math.Cos(angle)       • Math.Max(nu...
DateTime   • DateTime – представляє значення дати та часу.       • DateTime.Add(timeSpan)       • DateTime.AddDay(number)…...
Regex   Email pattern: “b[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}b”   • Regex.IsMatch(pattern, string)   • Regex.Replace(patte...
Collections      Collections:      • Hashtable      • ArrayList      • Queue      • Stack    Collections.Generic:    • Dic...
Nullable<T>       int? = Nullable<int>       Useful properties:       • HasValue       • Valuehttp://msdn.microsoft.com/en...
Path      • Path.Combine(path1, path2)      • Path.GetDirectoryName(path)      • Path.GetFileName(path)      • Path.GetExt...
DriveInfo        • DriveInfo.GetDrives()        • drive.DriveType {CDRom, Fixed, Unknown, Network, Removable ….}        • ...
Directory     • Directory.Create(folderPath)     • Directory.Move(folderPath, destinationPath)     • Directory.Delete(fold...
File      • File.Create(filePath)      • File.Move(filePath, filePathDestination)      • File.Copy(filePath, filePathDesti...
Encoding        •   Encoding.Default        •   Encoding.Unicode        •   Encoding.ASCII        •   Encoding.UTF32      ...
Streams       •   stream.Read(data, offset, count)                                      Stream       •   stream.Write(data...
Binary serialization  [Serializable]  public class MyObject  {          public int n1 = 0;          public int n2 = 0;    ...
XML serialization   public class MyObject   {           public int n1 = 0;           public int n2 = 0;           public S...
The end
Tortoise SVNhttp://tortoisesvn.net/
Upcoming SlideShare
Loading in …5
×

04 standard class library c#

1,815 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

04 standard class library c#

  1. 1. Стандартнабібліотека класів c#
  2. 2. Зміст1. Що таке Generic? Extension methods.2. Math3. DateTime, TimeSpan4. Regex5. Колекції. System.Collections, System.Collections.Generic.6. Nullable<T>, “type?”7. Path8. DriveInfo9. Directory10. File11. Encodings12. Streams13. Serializationdeserializations
  3. 3. Generics • Generic methods: • FirstOrDefault<T>(T[] array) • FirstOrDefault<T>(T[] array, T defaultValue) • Type inference: • int first = FirstOrDefault(new[] {3, 2, 1}); • default(T) expression • Type constraints: • Base type, class, struct, new() • Generic types: • Example: List<T>http://msdn.microsoft.com/en-us/library/ms379564(v=vs.80).aspx
  4. 4. Extension methods Simply static methods Used for conveniencehttp://msdn.microsoft.com/en-us/library/bb383977.aspx
  5. 5. Math • Math.Abs(number) • Math.Pow(number) • Math.Sin(angle) • Math.Cos(angle) • Math.Max(number1, number2) • Math.Min(number1, number2) • …http://msdn.microsoft.com/en-us/library/system.math.aspx
  6. 6. DateTime • DateTime – представляє значення дати та часу. • DateTime.Add(timeSpan) • DateTime.AddDay(number)…. • DateTime.ToString(format) (hh:mm:ss) • ToLocalTime() • ToUniversalTime() • DateTime.Now • DateTime.UtcNow • … • TimeSpan – представляє інтервали дати та часу. • TimeSpan.TotalMilliseconds • TimeSpan.Days • TimeSpan.TotalDays • …http://msdn.microsoft.com/en-us/library/system.datetime.aspx - DateTimehttp://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx - Custom DateTime Formats
  7. 7. Regex Email pattern: “b[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}b” • Regex.IsMatch(pattern, string) • Regex.Replace(pattern, string, newValue)http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx
  8. 8. Collections Collections: • Hashtable • ArrayList • Queue • Stack Collections.Generic: • Dictionary<TKey, TValue> • List<T> • Queue<T> • Stack<T> • LinkedList<T>http://msdn.microsoft.com/en-us/library/system.collections.aspx - Collectionshttp://msdn.microsoft.com/en-us/library/0sbxh9x2.aspx - Collections.Generic
  9. 9. Nullable<T> int? = Nullable<int> Useful properties: • HasValue • Valuehttp://msdn.microsoft.com/en-us/library/b3h38hb0.aspx
  10. 10. Path • Path.Combine(path1, path2) • Path.GetDirectoryName(path) • Path.GetFileName(path) • Path.GetExtension(path) • Path.GetFullPath(path) • Path.GetRandomFileName() • Path.GetTempFileName() • Path.GetTempPath()http://msdn.microsoft.com/en-us/library/system.io.path_methods.aspx
  11. 11. DriveInfo • DriveInfo.GetDrives() • drive.DriveType {CDRom, Fixed, Unknown, Network, Removable ….} • drive.DriveFormat {NTFS, FAT32} • drive. AvailableFreeSpacehttp://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
  12. 12. Directory • Directory.Create(folderPath) • Directory.Move(folderPath, destinationPath) • Directory.Delete(folderPath) && Directory.Delete(folderPath, true/*recursive*/) • Directory.Exists(folderPath) • Directory.GetFiles(folderPath, [search pattern])http://msdn.microsoft.com/en-us/library/system.io.directory.aspx
  13. 13. File • File.Create(filePath) • File.Move(filePath, filePathDestination) • File.Copy(filePath, filePathDestination) • File.Delete(filePath) • File.Exists(filePath) • File.WriteAllText(filePath, text) • File.WriteAllBytes(filePath, bytes) • File.AppendText(filePath, text) • File.ReadAllText(filePath) • File.ReadAllBytes(filePath)http://msdn.microsoft.com/en-us/library/system.io.file.aspx
  14. 14. Encoding • Encoding.Default • Encoding.Unicode • Encoding.ASCII • Encoding.UTF32 • … • Encoding.Convert(sourceEncoding, destinationEncoding, bytes) • encoding.GetBytes(string) • encoding.GetString(bytes)http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx
  15. 15. Streams • stream.Read(data, offset, count) Stream • stream.Write(data, offset, count) • stream.Length CryptoStream • stream.Seek(offset, SeekOrigin) • stream.Close() MemoryStream FileStream • StreamWriter – easy way to write into text files. • StreamReader – easy way to read text from files. • FileStream – easy way to work with binary files. Create FileStream: • constructor (new FileStream(path, FileMode, FileAccess)) • File.Create • File.Open • File.Writehttp://msdn.microsoft.com/en-us/library/system.io.stream.aspx - Streamhttp://msdn.microsoft.com/en-us/library/system.io.filestream.aspx - FileStream
  16. 16. Binary serialization [Serializable] public class MyObject { public int n1 = 0; public int n2 = 0; public String str = null; } Serizalization MyObject obj = new MyObject(); obj.n1 = 1; obj.n2 = 24; obj.str = "Some String"; IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(stream, obj); stream.Close(); Deserizalization IFormatter formatter = new BinaryFormatter(); Stream stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read); MyObject obj = (MyObject)formatter.Deserialize(stream); stream.Close();http://msdn.microsoft.com/en-us/library/72hyey7b(v=vs.80).aspx
  17. 17. XML serialization public class MyObject { public int n1 = 0; public int n2 = 0; public String str = null; } Serizalization MyObject obj = new MyObject(); obj.n1 = 1; obj.n2 = 24; obj.str = "Some String"; XmlSerializer serializer = new XmlSerializer(typeof(MyObject)); Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None); serializer.Serialize(stream, obj); stream.Close(); Deserizalization XmlSerializer serializer = new XmlSerializer(typeof(MyObject)); Stream stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read); MyObject obj = (MyObject)serializer.Deserialize(stream); stream.Close();http://msdn.microsoft.com/en-us/library/90c86ass(v=vs.80).aspx
  18. 18. The end
  19. 19. Tortoise SVNhttp://tortoisesvn.net/

×