SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Стандартна
бібліотека класів c#
Зміст
1.    Що таке Generic? Extension methods.
2.    Math
3.    DateTime, TimeSpan
4.    Regex
5.    Колекції. System.Collections, System.Collections.Generic.
6.    Nullable<T>, “type?”
7.    Path
8.    DriveInfo
9.    Directory
10.   File
11.   Encodings
12.   Streams
13.   Serializationdeserializations
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
Extension methods

                               Simply static methods

                                  Used for convenience




http://msdn.microsoft.com/en-us/library/bb383977.aspx
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
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 - DateTime
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx - Custom DateTime Formats
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
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 - Collections
http://msdn.microsoft.com/en-us/library/0sbxh9x2.aspx - Collections.Generic
Nullable<T>

       int? = Nullable<int>

       Useful properties:
       • HasValue
       • Value




http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx
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
DriveInfo

        • DriveInfo.GetDrives()




        • drive.DriveType {CDRom, Fixed, Unknown, Network, Removable ….}
        • drive.DriveFormat {NTFS, FAT32}
        • drive. AvailableFreeSpace




http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
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
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
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
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.Write
http://msdn.microsoft.com/en-us/library/system.io.stream.aspx - Stream
http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx - FileStream
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
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
The end
Tortoise SVN




http://tortoisesvn.net/

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Alex Bilbie
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
TO THE NEW | Technology
 
MongoDB Advanced Topics
MongoDB Advanced TopicsMongoDB Advanced Topics
MongoDB Advanced Topics
César Rodas
 
Data Modeling Deep Dive
Data Modeling Deep DiveData Modeling Deep Dive
Data Modeling Deep Dive
MongoDB
 

Was ist angesagt? (20)

File-Data structure
File-Data structure File-Data structure
File-Data structure
 
Tthornton code4lib
Tthornton code4libTthornton code4lib
Tthornton code4lib
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Python Files
Python FilesPython Files
Python Files
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction2011 Mongo FR - MongoDB introduction
2011 Mongo FR - MongoDB introduction
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
MongoDB (Advanced)
MongoDB (Advanced)MongoDB (Advanced)
MongoDB (Advanced)
 
"Solr Update" at code4lib '13 - Chicago
"Solr Update" at code4lib '13 - Chicago"Solr Update" at code4lib '13 - Chicago
"Solr Update" at code4lib '13 - Chicago
 
MongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with MorphiaMongoDB: Easy Java Persistence with Morphia
MongoDB: Easy Java Persistence with Morphia
 
Webinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real WorldWebinar: Data Modeling Examples in the Real World
Webinar: Data Modeling Examples in the Real World
 
Talk about ReactiveMongo at MSUG May
Talk about ReactiveMongo at MSUG MayTalk about ReactiveMongo at MSUG May
Talk about ReactiveMongo at MSUG May
 
MongoDB and Python
MongoDB and PythonMongoDB and Python
MongoDB and Python
 
Java File I/O
Java File I/OJava File I/O
Java File I/O
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
 
MongoDB Advanced Topics
MongoDB Advanced TopicsMongoDB Advanced Topics
MongoDB Advanced Topics
 
NoSQL store everyone ignored - Postgres Conf 2021
NoSQL store everyone ignored - Postgres Conf 2021NoSQL store everyone ignored - Postgres Conf 2021
NoSQL store everyone ignored - Postgres Conf 2021
 
CouchDB-Lucene
CouchDB-LuceneCouchDB-Lucene
CouchDB-Lucene
 
Data Modeling Deep Dive
Data Modeling Deep DiveData Modeling Deep Dive
Data Modeling Deep Dive
 

Ähnlich wie 04 standard class library c#

03 standard class library
03 standard class library03 standard class library
03 standard class library
eleksdev
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and models
Korea Sdec
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning Approach
Reza Rahimi
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
Paul Chao
 

Ähnlich wie 04 standard class library c# (20)

03 standard class library
03 standard class library03 standard class library
03 standard class library
 
Migrating from matlab to python
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Introduction to libre « fulltext » technology
Introduction to libre « fulltext » technologyIntroduction to libre « fulltext » technology
Introduction to libre « fulltext » technology
 
SDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and modelsSDEC2011 NoSQL concepts and models
SDEC2011 NoSQL concepts and models
 
Python redis talk
Python redis talkPython redis talk
Python redis talk
 
SMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning ApproachSMS Spam Filter Design Using R: A Machine Learning Approach
SMS Spam Filter Design Using R: A Machine Learning Approach
 
An Introduction to gensim: "Topic Modelling for Humans"
An Introduction to gensim: "Topic Modelling for Humans"An Introduction to gensim: "Topic Modelling for Humans"
An Introduction to gensim: "Topic Modelling for Humans"
 
Hadoop Overview & Architecture
Hadoop Overview & Architecture  Hadoop Overview & Architecture
Hadoop Overview & Architecture
 
Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Hadoop Tutorial with @techmilind
Hadoop Tutorial with @techmilindHadoop Tutorial with @techmilind
Hadoop Tutorial with @techmilind
 
Cascading introduction
Cascading introductionCascading introduction
Cascading introduction
 
Hadoop london
Hadoop londonHadoop london
Hadoop london
 
AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)AI與大數據數據處理 Spark實戰(20171216)
AI與大數據數據處理 Spark實戰(20171216)
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDC
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Using existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analyticsUsing existing language skillsets to create large-scale, cloud-based analytics
Using existing language skillsets to create large-scale, cloud-based analytics
 
2016 bioinformatics i_bio_python_wimvancriekinge
2016 bioinformatics i_bio_python_wimvancriekinge2016 bioinformatics i_bio_python_wimvancriekinge
2016 bioinformatics i_bio_python_wimvancriekinge
 
2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge
 
What is new in CFEngine 3.6
What is new in CFEngine 3.6What is new in CFEngine 3.6
What is new in CFEngine 3.6
 

Mehr von Victor Matyushevskyy (20)

Design patterns part 2
Design patterns part 2Design patterns part 2
Design patterns part 2
 
Design patterns part 1
Design patterns part 1Design patterns part 1
Design patterns part 1
 
Multithreading and parallelism
Multithreading and parallelismMultithreading and parallelism
Multithreading and parallelism
 
Mobile applications development
Mobile applications developmentMobile applications development
Mobile applications development
 
Service oriented programming
Service oriented programmingService oriented programming
Service oriented programming
 
ASP.Net MVC
ASP.Net MVCASP.Net MVC
ASP.Net MVC
 
ASP.Net part 2
ASP.Net part 2ASP.Net part 2
ASP.Net part 2
 
Java script + extjs
Java script + extjsJava script + extjs
Java script + extjs
 
ASP.Net basics
ASP.Net basics ASP.Net basics
ASP.Net basics
 
Automated testing
Automated testingAutomated testing
Automated testing
 
Основи Баз даних та MS SQL Server
Основи Баз даних та MS SQL ServerОснови Баз даних та MS SQL Server
Основи Баз даних та MS SQL Server
 
Usability
UsabilityUsability
Usability
 
Windows forms
Windows formsWindows forms
Windows forms
 
Practices
PracticesPractices
Practices
 
06.1 .Net memory management
06.1 .Net memory management06.1 .Net memory management
06.1 .Net memory management
 
06 LINQ
06 LINQ06 LINQ
06 LINQ
 
05 functional programming
05 functional programming05 functional programming
05 functional programming
 
#3 Об'єктно орієнтоване програмування (ч. 2)
#3 Об'єктно орієнтоване програмування (ч. 2)#3 Об'єктно орієнтоване програмування (ч. 2)
#3 Об'єктно орієнтоване програмування (ч. 2)
 
#2 Об'єктно орієнтоване програмування (ч. 1)
#2 Об'єктно орієнтоване програмування (ч. 1)#2 Об'єктно орієнтоване програмування (ч. 1)
#2 Об'єктно орієнтоване програмування (ч. 1)
 
#1 C# basics
#1 C# basics#1 C# basics
#1 C# basics
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

04 standard class library c#

  • 2. Зміст 1. Що таке Generic? Extension methods. 2. Math 3. DateTime, TimeSpan 4. Regex 5. Колекції. System.Collections, System.Collections.Generic. 6. Nullable<T>, “type?” 7. Path 8. DriveInfo 9. Directory 10. File 11. Encodings 12. Streams 13. Serializationdeserializations
  • 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. Extension methods Simply static methods Used for convenience http://msdn.microsoft.com/en-us/library/bb383977.aspx
  • 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. 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 - DateTime http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx - Custom DateTime Formats
  • 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. 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 - Collections http://msdn.microsoft.com/en-us/library/0sbxh9x2.aspx - Collections.Generic
  • 9. Nullable<T> int? = Nullable<int> Useful properties: • HasValue • Value http://msdn.microsoft.com/en-us/library/b3h38hb0.aspx
  • 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. DriveInfo • DriveInfo.GetDrives() • drive.DriveType {CDRom, Fixed, Unknown, Network, Removable ….} • drive.DriveFormat {NTFS, FAT32} • drive. AvailableFreeSpace http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx
  • 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. 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. 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. 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.Write http://msdn.microsoft.com/en-us/library/system.io.stream.aspx - Stream http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx - FileStream
  • 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. 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

Hinweis der Redaktion

  1. Важливість збереження UTCБаг з збереженням тільки дати. (ЮТС і потім проблема конвертацією до ЛокалТайм)
  2. The objects used as keys by a Hashtable are required to override the Object.GetHashCode method (or the IHashCodeProvider interface) and the Object.Equals method (or the IComparer interface).
  3. Path.Combine(“c:\\folder1\\”, “\\folder2\\fileName.txt”)GetDirectoryName(&apos;C:\\MyDir\\MySubDir\\myfile.ext&apos;) returns &apos;C:\\MyDir\\MySubDir‘GetFileName(&apos;C:\\mydir\\myfile.ext&apos;) returns &apos;myfile.ext‘// GetFullPath(&apos;mydir&apos;) returns &apos;C:\\temp\\Demo\\mydir&apos;// GetFullPath(&apos;\\mydir&apos;) returns &apos;C:\\mydir&apos;
  4. Rename - move
  5. File.Create returns Stream!Rename - move
  6. fs.Seek(offset, SeekOrigin.Begin)fs.Write(data, 0, data.length)
  7. Приавила серіалізаціїАтрибув [Serializable]Public\\private\\protected клас
  8. Приавила серіалізаціїДефолтний конструкторpublic класpublic проперті\\філдиЯкщо під час десеріалізації не знаходиться властивість у даних, то в об’єкті вона буде null