Those years "deep. NET platform and C # programming "

Source: Internet
Author: User

First, in-depth. NET Framework

The 1..NET framework has two components: the CLR (Common Language Runtime) and the FCL (Framework class Library), the CLR is the foundation of the. NET Framework

2. Framework Core Class Library:

System.Collections.Generic: Generic operation

System.IO:IO Flow operation

System.Net: Network Programming

System.Data:ADO. NET structure of the class access

System.Windows.Forms: Form Actions

System.Drawing: Graphics operations

Second, in-depth C # data types

1. struct: struct is a struct-decorated class, struct is a value type (enumeration is also a value type)

public struct Student
{
}

2. Unpacking and Packing:

Boxing: Converting a value type to a reference type

Object o=1;

Unpacking: Converting a reference type to a value type

int num= (int) o;

3. Value passing and reference passing (with or without ref adornments)

A. When there is a ref modifier, the modified value is permanently preserved

B. When no ref modifier is a value type, the modified value is not persisted

C. When no ref modifier is a reference type, the modified value is persisted

Iii. Generic Collections

1. Concept of the collection:

A collection is a container that puts data of a bunch of data types together, and arrays are very similar things.

2. Classification of collections and methods of declaration

A. The collection is divided into non-generic and generic collections, non-generic and single-column (ArrayList) and double-row (Hashtable), and generics are also separated (list<t>) and double-column (dictionary<k,v>).

The T data type of a single column can be of type object, and the k,v of two columns can also be of type Object

B. Declaration of a collection

ArrayList list=new ArrayList ();

Hashtable list=new Hashtable ();

List<t> list=new list<t> ();

Dictionary<k,v> list=new dictionary<k,v> ();

3. Methods and properties of the collection

1.ADD (), ways to add data

2.Remove (), the method of deleting data, () filled with a whole piece of data, single-column collection of the deletion, the collection will automatically maintain the data, so that the collection will not appear an index value is empty

3.RemoveAt (), also is the method of deleting data, () filled in the index (single row) Double column No RemoveAt () method,

4.Clear (), empties all data from the collection

5.Count attributes, you can get a collection of several data

6.Capacity properties, the capacity of the collection, the capacity of the collection is multiplied (twice times), Count is 0 o'clock, capacity is 0,count to 1 o'clock, capacity is 4

7.Contains (), a single-column collection to determine whether a data exists

8.ContainsKey (), double column to determine if a key value exists

9.ContainsValue (), double-column determines if a value is present

4. The traversal method of the collection

Hashtable and dictionary traversal is different, when traversing the value type, Hashtable need to do type conversion (unboxing, boxing)

HashTable:

(1). Traverse the foreach (string item in list) through the key value. Keys) {Console.WriteLine (List[item]);}

(2). Traverse the foreach (Student item in list) by value. Values) {Console.WriteLine ((Student) item. Name); }

(3). Traverse the foreach (DictionaryEntry item in list) {Console.WriteLine (item) through the whole double-column set. Key); Console.WriteLine ((Student) item. Value). Name); }

Dictionary:

(1). Traverse the foreach (string item in list) through the key value. Keys) {Console.WriteLine (List[item]);}

(2). Traverse the foreach (Student item in list) by value. Values) {Console.WriteLine (item. Name); }

(3). Through the overall traversal of the foreach (keyvaluepair<t,v> item in list) {Console.WriteLine (item. Key); Console.WriteLine (item. Value). Name); }

Iv. methods of in-depth classes

1. Method overloading: By passing the different parameters to call different methods, the same method name, parameter types, parameter order, the number of parameters is different, and the return value Independent

Parameter types are different:

public void Play (int num) {};

public void Play (string name) {};

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) {};

Is independent of the return value:

public string Play (int num) {};

public int Play (int num) {};

2. Construction of class: Same as Class name, no return value

Non-parametric construction:

public class Student

{

Public Student () {};

}

Structure with parameters: With a parameter structure, the non-parametric construction of the class must be written out

public class Student

{

public string Name {get; set;}

Public Student () {};

Public Student (string name) {this. Name=name};

}

3. Interaction between objects

A TV class:

public class Tv

{

public void Play () {};

}

A TV Tool class

public class Tvtool

{

public void Play ()

{

TV t=new TV ();

T.play ();

};

}

In the main program:

Tvtool tool=new Tvtool ();

Tool. Play ();

So that only control one class to control other classes

V. Inheritance and polymorphism

1. Inheritance: subclasses inherit the parent class, and subclasses can use the parent class's properties and methods, inheriting with ":" (colon) implementation

Parent class:

public class Mans

{

int age;

String name;

public void Say ()

{

};

}

Sub-class:

public class Student:man

{

public void Play ()

{

method, you can use the properties and methods of the parent class

age=1;

Name= "Zhang San";

Say ();

};

}

2. Virtual method to achieve polymorphism: through the subclass of the method of the parent class, to achieve polymorphism, so that a method to achieve different effects

Parent class:

public class Mans

{

public virtual void Say ()

{

}

}

Sub-class:

public class Student:man

{

public override void Play ()

{

I'm a student.

}

}

public class Super:man

{

public override void Play ()

{

I'm a Superman.

}

}

Vi. in-depth polymorphism

1. The Richter principle: Parent-class power subclasses do not affect programs

2. Is and AS

The IS operator is used to check the object and the specified type

The as operator is used for type conversions between two objects

3. Abstract class to achieve polymorphism

Parent class:

Public abstract class Mans

{

public abstract void Say ()

{

}

public void Play () {}

Abstract classes can have common methods

}

Sub-class:

public class Student:man

{

public override void Play ()

{

I'm a student.

}

}

public class Super:man

{

public override void Play ()

{

I'm a Superman.

}

}

Vii. operation of XML

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

}

The XML data can be placed in the collection

You can also parse the XML data through the indexer

2. About the properties of the XmlNode object

InnerText: The value of the current node

Name: Names of the current nodes

ChildNodes: All child nodes of the current node

3.treeView binding Node

TreeNode tn = new TreeNode (item);
Tn. Tag = Schedule.items[item]. Movie;
Treeview.Nodes.Add (TN);

Viii. operation of files

1. Read and Write files

Write:

FileStream fs=new FileStream (path,filemode.create);

StreamWriter sw=new StreamWriter (FS);

Sw. Writer (requires some text);

Sw.     Close (); Rear-open first-off flow

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 properties

Exists: Pan judged whether there was

Extension: Suffix name

Naem: File name

FullName: File Address

Those years "deep. NET platform and C # programming "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.