C # Sort notes on knowledge,
This section briefly introduces some common attributes, as well as explanations and examples of some terms, which are not comprehensive and I hope readers can add more.
1. Overload: The function name is the same, and the number or type of parameters are different;
public void MyDog(string s); public void MyDog(int i); public void MyDog(string s,int i);
2. Inheritance: one class inherits the members of another class. The inherited class is called a base class and the inherited class is called a derived class;
Class A {member;} class B: A // The method of inheritance. derived class: base class {member ;}
3. Polymorphism: the override method of the parent class can be rewritten in the subclass. The override type must be defined.
Public override DuoTai () {Console. WriteLine ("The 'duotai' method in the parent class can be rewritten here ");}
4. Interface: The implementation provides a specification and constraint, the keyword Interface
1. modifier: new public protected internal private; 2. modifiers are not allowed before interface members; 3. A class can inherit multiple interfaces. 4. format: interface modifier keyword interface name public interfa JieKou {void g (); // interface member ;}
5. abstract class: keywords (abstract)
Public abstract class PiSaAll {member ;}
6. encapsulation (class attributes): Package and encapsulate a group of data.
public string MianBing { get; set; } public string Shui { get; set; }
7. constructor: it has the same name as the class and is public-modified. No return value (not void)
Class Dog {public Dog (string s, int I) // constructor syntax {Console. WriteLine ("this is a puppy! Name: {0}, {1} years old ", s, I) ;}} Mian: Dog dog = new Dog (" too many ", 4 );
8. member access controller:
1. public (common): allows access by members of any class. 2. private: cannot be accessed by members of other classes, including the derived classes. 3. internal (Internal Member): it can only be accessed by members of classes in the Assembly, while members of classes outside the Assembly (including derived classes) are not allowed to access it. 4. protected: it can be accessed by members of this class or derived class, and members of other classes are not allowed to access it.
9. Statements used to connect to the database:
1. string conStr = "Data Source=IUCL8V4Y7NW5IRA\\SQLEXPRESS;Initial catalog=BookShopPlus;User Id=sa;Pwd=sa123"; 2. static string s = @"server=MY-20150918RBSF;database=Beauty;Integrated Security = true"; 3. static string s = ConfigurationSettings.AppSettings["dbinfo"].ToString();
10. Exception Handling:
1. try{}catch{} 2. try{}catch{}finally{} 3. using(SqlConnection con = new SqlConnection(conStr)){}
11. namespace:
1. using System. Data. SqlClient ;=> used for sqldatabase 2. using System. Data ;=> Data Class 3. using System. Collections ;=> ArrayList Array
12. ArrayList: ① is equivalent to an advanced dynamic Array, an upgraded version of the Array class.
② It is a convenient container class for Traversing arrays and can store any reference type or value type.
ArrayList arr = new ArrayList (); ArrayList arr1 = new ArrayList (30); ==> it can be added to more than 30 Student class arr. add (12) ;=> define the int type Class Student {arr. add (true) ;=> define bool type public int No {get; set ;} arr. add ("Hello") ;=> define the string type public string Name {get; set ;}student st = new Student () ;=> instantiate Student class} st. no = 1001 ;=> assign st to No in st. name = "zhangsan" ;=> assign arr to the Name in the st. add (st) ;=> Add the value of st to arr. removeAt (1) ;=> Delete the second arr in the array. insert (1, "World") ;=> Insert data World for (int I = 0; I <arr. count; I ++) {Console. writeLine (arr [I]) ;=> for convenient loop array}
13. Hashtable type: two parameters affect its performance ==> initial capacity and loading factor.
Hashtable ht = new Hashtable (); ht. add ("0531", "Jinan City"); ht. add ("0532", "Qingdao"); ht. add ("0536", "Weifang city"); ht. add ("0631", "Weihai"); Console. writeLine (ht ["0531"]) ;=> the output subscript is 0531. Here it is "Jinan City"; Console. writeLine (ht. count) ;=> length of the output Hashtable array, 4 here;
14. ICollection type: it is an enhanced interface of IEnumerable. It provides synchronous processing and value assignment functions.
Hashtable ht = new Hashtable (); ht. add ("0531", "Jinan City"); ht. add ("0532", "Qingdao"); ht. add ("0536", "Weifang city"); ht. add ("0631", "Weihai"); ICollection keys = ht. keys ;=> get all the keys in Hashtable. This is not a method, so there is no parentheses foreach (string k in keys) {Console. writeLine ("{0} ----- {1}", k, ht [k]);}
15. IEnumerator iterator (with Hashtable)
Hashtable ht = new Hashtable (); ht. add ("0531", "Jinan City"); ht. add ("0532", "Qingdao"); ht. add ("0536", "Weifang city"); ht. add ("0631", "Weihai"); ICollection keys = ht. keys ;=> get all the keys in Hashtable. This is not a method, so there is no bracket IEnumerator ie = keys after keys. getEnumerator () ;=> return the enumerated Number of the access set while (ie. moveNext () ==> the number of enumerations is pushed to the next element of the set {Console. writeLine (ie. current) ;=> get the Current element Console in the set. writeLine ("{0} ----- {1}", ie. current, ht [ie. current]);}
16. IEnumerator iterator (with ArrayList)
ArrayList arr1 = new ArrayList (); arr. add (12) ;=> define the int type arr. add (true) ;=> define the bool type arr. add ("Hello") ;=> define the string type arr. insert (1, "World") ;=> Insert the string "World" IEnumerator ie = keys. getEnumerator () ;=> return the enumerated Number of the access set while (ie. moveNext () ==> the number of enumerations is pushed to the next element of the set {Console. writeLine (ie. current) ;=> get the Current element Console in the set. writeLine ("{0} ----- {1}", ie. current, ht [ie. current]);}
17. List generics: ① the specific parameters of classes and methods can be declared in the Customer Code for implementation.
② It can work with any data type (class, method ).
Define the class of Student sorted by Student ID: class MyStudentCompare: IComparer <Student >=> defines the implementation method for comparing two objects {public int Compare (Student st1, Student st2) {return st1.No-st2.No;} defines the Student Class: Class Student {public int No {get; set;} public string Name {get; set ;}} defines the Student generic: list <Student> list = new List <Student> () ;=> defines the generic list of Student types. add (new Student (1002, "Zhang San 2"); list. add (new Student (1004, "James 4"); list. add (new Student (1003, "James 3"); list. add (new Student (1001, "Zhang San 1"); list. add (new Student (1005, "Zhang San 5"); list. sort (new MyStudentCompare () ;=> call the defined class method foreach (Student st in list) {Console. writeLine (st. toString ());}
18. Sort list type: bidirectional list with high efficiency. You can only find the first and last columns.
Generic list <int> lnk = new generic list <int> () ;=> defines generic lnk of the int type. addFirst (1); lnk. addLast (2); lnk. addLast (3); foreach (var lnk1 in lnk) ==> var can recognize types. var itself is also a type {Console. writeLine (lnk1);} publish listnode <int> first = lnk. first; ==> obtain the Console of the First node. writeLine (first. value); => output the Value of the first node.
19. Dictionary: The using System. Collections namespace must be referenced.
Description: ① ing from a set of keys to a set of values. Each add item is composed of a value and its associated keys. ② any key must be unique. ③ The key cannot be null reference null. If the value is of the reference type, it can be null. ④ The key and value can be of any type (string, int, custom, class ). dictionary <int, string> dic = new Dictionary <int, string> (); dic. add (0531, "Jinan"); dic. add (0532, "Qingdao"); ICollection <int> key2 = dic. keys ;=> get the set of Keys in dic foreach (var k in key2) ==> var is a newly added function of 3.0 {Console. writeLine ("{0} ---- {1}", k, dic [k]);}
20. HashSet: it is an unordered set and cannot have duplicate values.
HashSet <string> hs = new HashSet <string> () ;=> you can add a value of the string type hs. add ("12345"); hs. add ("Apple"); hs. add ("1234"); hs. add ("Hello"); hs. add ("123"); hs. add ("World"); IEnumerator <string> ie = hs. getEnumerator (); while (ie. moveNext () {Console. writeLine (ie. current);} Console. writeLine (hs. count );
21. Custom generic:
public class Person <T> { public T No {get ; set ;} }
Note: This article is purely written in notepad and may produce some code errors. I hope you can correct them !~