In those years [go deep into the. NET platform and C # programming ],
I. go deep into the. NET Framework
1. the. NET Framework has two components: CLR (runtime in public languages) and FCL (framework class library). CLR is the basis of the. NET Framework.
2. core framework Class Library:
System. Collections. Generic: Generic operation
System. IO: IO stream operations
System. Net: Network Programming
System. Data: Class access in the ADO. NET Structure
System. Windows. Forms: Form operations
System. Drawing: Graphical operations
Ii. go deep into C # Data Types
1. struct: struct is a class modified by struct, struct is a value type (enumeration is also a value type)
Public struct Student
{
}
2. unpacking and packing:
Packing: converts a value type to a reference type.
Object o = 1;
Binning: converts a reference type to a value type.
Int num = (int) o;
3. Value Transfer and reference transfer (with or without ref modifier)
A. When there is a ref modifier, the modified value will be permanently retained
B. If no ref modifier is specified, the modified value is not retained permanently.
C. When there is no ref modifier, it is of the reference type and the modified value will be permanently retained.
Iii. Generic set
1. Concept of set:
A collection is a container that puts a bunch of data types together. It is very similar to an array.
2. Classification and declaration of Sets
A. a set can be divided into non-generic and generic sets. Non-generic sets can be divided into single-column (ArrayList) and double-row (Hashtable), and the generic set can also be divided into single-column (List <T>) and double (Dictionary <K, V> ).
The T data type of a single column can be object type, K or V of double row can also be object type.
B. Set Declaration
ArrayList list = new ArrayList ();
Hashtable list = new Hashtable ();
List <T> list = new List <T> ();
Dictionary <K, V> list = new Dictionary <K, V> ();
3. Set methods and attributes
1. Add () to Add data
2. remove (): The method for deleting data. () indicates the entire data. When a single column set is deleted, the set automatically maintains the data, in this way, the set does not show that the value of an index is null.
3. RemoveAt () is also the method for deleting data. () indicates that the index (Single Column) has no RemoveAt () method,
4. Clear (): clears all data in the set.
5. Count attribute to obtain the number of data records in the set.
6. The Capacity attribute indicates the Capacity of the set. The Capacity of the Set increases exponentially (twice). When Count is 0, Capacity is 0, and Count is 1, Capacity is 4.
7. Contains (), a single column set used to determine whether a data exists
8. ContainsKey (), double row to determine whether a Key value exists
9. ContainsValue (), double row to determine whether a Value exists
4. Set Traversal method
The difference between HashTable and Dictionary traversal is that, when traversing value types, HashTable needs to perform type conversion (unpacking and packing)
HashTable:
(1). Traverse foreach (string item in list. Keys) {Console. WriteLine (list [item]) through the Key value;}
(2). Traverse foreach (Student item in list. Values) {Console. WriteLine (Student) item. Name) through value );}
(3 ). traverse foreach (DictionaryEntry item in list) {Console. writeLine (item. key); Console. writeLine (Student) item. value ). name );}
Dictionary:
(1). Traverse foreach (string item in list. Keys) {Console. WriteLine (list [item]) through the Key value;}
(2). Traverse foreach (Student item in list. Values) {Console. WriteLine (item. Name );}
(3 ). traverse foreach (KeyValuePair <T, V> item in list) {Console. writeLine (item. key); Console. writeLine (item. value ). name );}
Iv. In-depth Methods
1. Method overloading: different methods are called based on different passed parameters. The method names are the same, the parameter types are different, the parameter order is different, and the number of parameters is different, which is irrelevant to the return value.
Different parameter types:
Public void Play (int num ){};
Public void Play (string name ){};
The Parameter order is different:
Public void Play (int num, int age ){};
Public void Play (int age, int num ){};
The number of parameters is different:
Public void Play (int num ){};
Public void Play (string name, int num ){};
It has nothing to do with the return value:
Public string Play (int num ){};
Public int Play (int num ){};
2. Class Construction: Same as the class name, no return value
No parameter structure:
Public class Student
{
Public Student (){};
}
Construction with parameters: it has a construction with parameters and must write out the construction without parameters of the class.
Public class Student
{
Public string Name {get; set ;}
Public Student (){};
Public Student (string name) {this. Name = name };
}
3. Interaction between objects
A TV:
Public class TV
{
Public void Play (){};
}
One TV Tool
Public class TvTool
{
Public void Play ()
{
TV t = new TV ();
T. Play ();
};
}
In the main program:
TvTool tool = new TvTool ();
Tool. Play ();
So only one class can be controlled to control other classes.
5. Inheritance and Polymorphism
1. Inheritance: The subclass inherits the parent class, And the subclass can use the attributes and methods of the parent class. The inheritance is implemented using the colon (:).
Parent class:
Public class Man
{
Int age;
String name;
Public void Say ()
{
};
}
Subclass:
Public class Student: Man
{
Public void Play ()
{
You can use the attributes and methods of the parent class.
Age = 1;
Name = "James ";
Say ();
};
}
2. Implement polymorphism through Virtual Methods: Implement polymorphism through subclass re-parent methods to achieve different effects through a method
Parent class:
Public class Man
{
Public virtual void Say ()
{
}
}
Subclass:
Public class Student: Man
{
Public override void Play ()
{
I am a student
}
}
Public class Super: Man
{
Public override void Play ()
{
I'm a superman
}
}
6. Deep Polymorphism
1. Lee's principle: parent class strength subclass will not affect the program
2. is and
The is operator is used to check objects and specified types.
The as operator is used for type conversion between two objects.
3. Implement polymorphism in abstract classes
Parent class:
Public abstract class Man
{
Public abstract void Say ()
{
}
Public void Play (){}
Abstract classes can have common methods
}
Subclass:
Public class Student: Man
{
Public override void Play ()
{
I am a student
}
}
Public class Super: Man
{
Public override void Play ()
{
I'm a superman
}
}
VII. Xml operations
1. Xml Parsing
XmlDocument doc = new XmlDocument ();
Doc. Load (path );
XmlNode root = doc. DocumentElement;
Foreach (XmlNode item in root. ChildNodes)
{
Switch (item. Name)
{
Case "Name ":
MovieName = item. InnerText;
M. MovieName = movieName;
Break;
Case "Poster ":
PlayBill = item. InnerText;
M. Poster = playBill;
Break;
}
You can place Xml data in a collection.
You can also use the indexer to parse Xml data.
2. attributes of the XmlNode object
InnerText: current node Value
Name: Name of the current node
ChildNodes: all child nodes of the current node
3. Bind The treeView Node
TreeNode tn = new TreeNode (item );
Tn. Tag = Schedule. Items [item]. Movie;
Treeview. Nodes. Add (tn );
8. File Operations
1. Read and Write files
Write:
FileStream fs = new FileStream (path, FileMode. Create );
StreamWriter sw = new StreamWriter (fs );
Sw. Writer (required text );
Sw. Close (); enable the stream first
Fs. Close ();
Read:
FileStream fs = new FileStream (path, FileMode. Open );
StreamWriter sw = new StreamWriter (fs, Ending. Default );
String txt = sw. ReadToEnd ();
Sw. Close ();
Fs. Close ();
2. related attributes
Exists: Pan determines whether there is
Extension: suffix
Naem: File Name
FullName: file address