1. Enumeration: The essence is the class
- If you assign an int value to the first enumeration, the following enumeration items are incremented sequentially
- The enumeration can be strongly converted to the Int value he represents.
- C # Enumeration entries are constants (you can view the IL source of literal with reflector)
- Because the enumeration has a corresponding int value, switch treats him as an int.
- Methods, properties, events cannot be defined
- When multiple enumerations have the same value, the last enumerated item is returned when the value is strongly turned
2. IEnumerable interface
As long as the interface is implemented, it can be traversed using foreach. The essence of the Foreach loop is to call this interface to return an iterator, which invokes the MoveNext () method of the iterator to implement the loop.
Source:
{ IEnumerator GetEnumerator (); // returns an iterator } publicinterface ienumerator{ bool MoveNext ( ); Object Get ; } void Reset ();}
The above is not difficult to see:
The IEnumerable interface primarily includes the Getenumerable method (gets the iterator object), the MoveNext method (checks for the existence of the next element of the loop), and the GetCurrent method (gets the element that is currently looping to)
3. CollectionBasic Concepts
A collection is a container that can pack a lot of things. Mainly classified as non-generic sets and generic collections
ArrayList--a object[] array in which the data is actually stored, the corresponding generic is list<t>
hashtable-- A non-generic set of key-value pairs that corresponds to a generic type of dictionary<tkey,tvalue>
different points and pros and cons of dynamic arrays and generic collections:
Dynamic arrays have no constraints on the elements, and you can add anything you want. The underlying reason is that it is an array of type object that stores data internally.
A generic collection is a collection with element type constraints (a constraint on the addition of elements)
Generic collections Avoid performance losses from boxing, unboxing, and parameter type checking when adding elements
Common Methods
Add (), AddRange (), Insert (), Insertrange (), remove (), removeAt ()
Reverse ()--reverses the elements in the collection
4. Hash tableinternal mechanism:
HashTable, a set of key-value pairs, within which is an array of struct bucket[]. There are three things: the key, the value, the key of the Harrow code
Data mainly stored in: private bucket[] buckets;
Private struct bucket{ publicobject key; Public Object Val; Public int Hash_coll;}
Access operation:
The principle of storage: The subscript is calculated based on the hash value of key. When we add an element to Hashtable, the subscript of the element stored in the Hashtable array is calculated based on the hash value of the added key (but because the hash value takes the modulo group length, it certainly does not exceed the current array length).
The hashcode that each object calculates is not unique. There is a possibility that multiple objects appear hashcode the same. Resolution Mechanism:
A, once again hash
B, bucket mode, two objects of the same hashcode are mounted in a unified location
C, when added, the container array in the Hashtable is full, then twice times the array expansion
principle of Value: when we take elements from Hashtable (according to Key), we will calculate the subscript of the element to be taken according to the hash value of the key, and compare the value of the key in the element and the key parameter that is currently looking for equality. Also compare the references of two keys in the same order. If all is satisfied, determine which element to fetch.
5. Generic collection
Reference namespace: System.Collections.Generic
List<t>--t is the type of storage
Dictionary<k,v>
6. Performance comparison of List<t> and ArrayList
ArrayList stored value types need to be boxed conjecture, while storage reference types require type conversions, and list<t> obviously do not require these additional overhead, high performance is obvious
7. Use time of Try statement block
Network operations (sockets), File operations (IO-related), database operations, Division operations (when the divisor is 0), forcing type conversion operations
8. Windows Form program related files
Designer.cs Design class and foreground two classes are sibling relationships (partial)
9. Path Class
Changeextension (Modify the suffix of the file, "modify" supports the string level, did not really rename the file)
combine--to synthesize two paths one path "Automatic Processing of path separators"
getdirectoryname--get the path name of the file
getextension--to get the file name extension
getfilename--get the file name part of the path
getfilenamewithoutextension--gets the file name of the extension removed
getfullpath--get the full path of the file, you can get the absolute path according to the relative path
gettempfilename--to get a unique temporary file name
gettemppath--get the path to the Temp folder
............
10. Operation folder, directory
delete--Delete Directory "Recursive indicates whether to delete recursively"
exists--determine if a directory exists
move--Mobile
getdirectories+ to get a subdirectory under a directory
getfiles--get a file in a directory
............
11. Operation Files
file--operation files, static classes, the overall operation of the file. Copy, delete. Shearing, etc.
appendalltext--Append the text contents to the file path "If the file does not exist, create"
exists--determine if the file path exists
readalllines--reading a text file into an array of strings
readalltext--reading a text file into a string
writealltext--Save the text contents to the file path, overwriting the old content
copy--file Copy "True indicates" overwrite "when the file exists, and if not true, the file is reported as abnormal"
create--Creating a file
delete--error if file is not present
A "class" of the directoryinfo--folder to describe a Folder object
getparent--get the parent directory of the Directory
fileinfo--folder, used to describe a folder object
Need to note:
Gets the current EXE file execution path with assembly.getexecutingassembly (). Location, do not use Directory.GetCurrentDirectory (), because getting the current working directory of the program, this path may change
Modify the text encoding to obtain the encoding by getencoding
12. File Stream
filestream--any type
streamwriter--String Write
streamreader--String Read
13. The nature of using statements
The essence is a try{...} Finally statement block
All classes that use the Using keyword to free resources must implement the IDisposable interface
Close executes Dispose () and reclaims the object
Using a using statement block does not catch the exception, because the using only does the try......finally operation, and there is no catch statement block, so you also add the Try......catch block in the using statement block to catch the exception
14. Serialization and deserialization
Serialization characteristics
Binary Formatter
Serialization: binary Formatter, which saves the fields and values in the object as "text" in the form of text
[Serializable]
BinaryFormatter class method
serialize--object graph serialized into stream
deserialize--the object from the stream, returning the object with a deserialized value
Serialization needs to be noted:
A, yes, the serialized type must be marked as: [Serializable]
b, the parent class of this type must also be marked as: [Serializable], when reflection has a parameter must be "whether to look for the parent class object"
C, the type of all members of the type must also be marked as: [Serializable]
D, serialization only has a field sequence number in the class (only some state information can be serialized)
deserialization: binary Formatter, first create an identical object, and then see the value of the field saved in "text" set to the field. Use reflection technology to create a new object based on the class name in the Text (field, field value, class name) information, and set the value of a field to the new object
dotnet Knowledge Point Summary four (note consolidation)