DotNet knowledge forty

1, enumerate: the essence is the class
if for the first enumeration assign an int value, then the back of the enumeration in ascending order of
enumeration can be converted to int strong values he represents
the C # enumerations are constants ( IL can see the literal source) with Reflector
because an int value has a corresponding enumeration, so Switch int see him as
not define methods, properties, events
plurality enumeration has the same value, when the value strong turn, returns the last of enumeration
2, IEnumerable interfaces
  as long as implements this interface, you can use foreach to traverse. foreach loop essence is to call this interface to return an iterator, call the iterator's MoveNext () method can achieve the cycle.

  Source:

Copy the code
{
the IEnumerator the GetEnumerator (); // returns an iterator
}

public interface the IEnumerator
{
BOOL the MoveNext ();
Object Current {GET;}
void the Reset ();
}
copy the code
  above is easy to see:

  IEnumerable interface including GetEnumerable process (acquisition iterator object), MoveNext method (check for the next cycle element), GetCurrent process (recycled to obtain the current element)

3, a collection of
  basic concepts
    set is a container can hold a bunch of things. It is divided into a set of non-generic and generic collection

    ArrayList-- which real data is stored in a Object [] array, which corresponds to a generic List <T>

    HashTable-- non-generic set of key-value pairs, which corresponds to a generic Dictionary <TKey, TValue>

  Dynamic arrays and differences, advantages and disadvantages generic collections:

      Dynamic arrays do not have any constraints on the elements you want to add anything. The fundamental reason is because it is an internal data storage array of type Object.

      With generic element type is the set of constraints (there is a constraint on the inside of the added element)

      Generic collection to avoid packing, unboxing performance cost, while adding elements to be checked Parameter Type

  Common methods
    add (), AddRange (), Insert (), InsertRange (), remove (), removeAt ()

    Reverse () - reversing the elements in the collection

4, the hash table
  internal mechanisms:
    the HashTable, a set of key-value pairs, which is an array of structures internal bucket []. There are three things: keys, values, key hash code

    Data stored in the main: private bucket [] buckets;

struct bucket Private
{
public Object Key;
public Object Val;
public int hash_coll;
}
  access operation:

    Principle storage: the index value is calculated according to the key of the hash. When we element to the HashTable Add, the elements stored in the array index where the HashTable is calculated based on the hash value added Key (but because hash value modulo the length of the array, it certainly does not exceed the current length of the array) .

    Each object counted out Hashcode not unique. There may be more of the same objects HashCode. Settlement Mechanism:

      a, once again hash

      B, bottled mode, two identical objects hashcode uniform loading position

      c, when new, HashTable in an array of container is full, places twice the expansion of the array

    Value principle: When we take elements from the HashTable where (according to key to take), according to the hash value of the index will be calculated to take the key elements and compare hash values ​​of the elements in the key and the key parameters of the currently looking for equality, but also to compare the two key references are the same. If you are satisfied, it is determined to find the elements to be taken.

5, generic collection
  referenced namespaces: System.Collections.Generic

  List <T> - T is the type of storage

  Dictionary<K,V>

. 6, List <T> and ArrayList performance comparison
  ArrayList stored boxed value types need conjecture, stored reference type requires conversion type, and List <T> obviously not need these extra cost, high performance apparent

7, using try block time
  network operation (socket), file operation (IO related), database operations, division operation (time division by zero), cast operation

8, Windows Form program documents
  designer.cs design classes and reception classes is the relationship between two brothers class (partial)

9, Path class
  ChangeExtension (suffix modify the file, "Edit" to support the string level, not really renaming files)

    Combine-- the two paths into one path of the automatic processing path [separators]

    GetDirectoryName-- get the file path name

    GetExtension-- get the file extension

    GetFileName-- get file path of the file name

    GetFileNameWithoutExtension-- obtain the removal of the file name extension

    GetFullPath-- get the full path to the file, you can get the absolute path of the relative path

    GetTempFileName-- get a unique temporary file name

    GetTempPath-- get the temporary folder path

    …………

10, operating folders, directories
  Delete-- delete directories recursively delete [] indicates whether recursive

  Exists-- determine whether a directory exists

  move-- move

  GetDirectories + get subdirectories under a directory

  GetFiles-- get the files in a directory

  …………

11, the operation file
  File-- manipulating files, static classes, the overall operation of the document. Copy, delete. Shear

  AppendAllText-- text contents will be appended to the file path in the [If the file does not exist, create]

  Exists-- determine whether there is a file path

  ReadAllLines-- read a text file into a string array

  ReadAllText-- read a text file into a string

  WriteAllText-- Save the text contents to a file path, it overwrites the old contents

  Copy-- file copy [true means that when the file exists "cover", if not true, the reported abnormal when file exists]

  Create a file Create--

  Delete-- If the file does not exist error

  DirectoryInfo-- a folder "class" is used to describe a folder object

  GetParent-- get the parent directory directory

  FileInfo-- folder, a folder object to describe

  requires attention:

    Gets the path of the current exe file executed by Assembly.GetExecutingAssembly (). Location, do not use Directory.GetCurrentDirectory (), because the program is to obtain the current working directory, the path may become

    Modify text of the coding obtained by encoding GetEncoding

12, the file stream
  FileStream-- any type

  StreamWriter-- write string

  StreamReader-- string read

13, essentially using statement
  is essentially a try {......} finally statement block

  Using all the classes you want to use keywords to release resources must implement the IDisposable interface

  Close to perform the Dispose () and recovered objects

  Use Using statement block does not catch an exception, because there Using only a try ...... finally operation, and there is no catch block, so the using statement block also add their own try ...... catch block to catch an exception

14, serialization and deserialization
  Serialization characteristics

  Binary formatter

  Serialization: binary formatter object in the field and value "text" manner saved into a text

    [Serializable]

    BinaryFormatter class method

      Serialize-- graph serialization to the object in the stream

      Deserialize-- serialized objects made from the stream, the returned object is deserialized obtained

    Serialization Note:

      a, die serialized type must be marked as: [Serializable]

      b, the type of the parent class must also be marked as: [Serializable], when there is a reflected parameter must be "whether Looking parent class object"

      c, all members of the type of that type must also labeled: [Serializable]

      d, serialization of only the sequence number field in the class (serialized some state information only)

  De-serialization: binary formatter, first create an identical object, and then set the value to see "text" in the field of preservation of the field. According to text (fields, field values, class names) in the name of the class information, creating a new object using reflection techniques, and set the value of a field to a new object

Guess you like

Origin www.cnblogs.com/Mr-Prince/p/12104607.html