C # has a lot of features, but the ordinary work of the opportunity to use a little, today have time to try to use a bit, wrote a code, which used the indexer, delegate, extension method, generics, anonymous type, anonymous method, object set initializer, immediately feel very high-end wood has ~ ~ ~
public class User {public int UserID {get; set;} public string UserName {get; set;} public int Age {get; set;} } public class Mylist<t> {private t[] data; Public MyList () {data = new t[0]; } public int Count {get {return data. Length; }} public void Add (T t) {t[] temp = data; data = new T[temp. Length + 1]; Temp. CopyTo (data, 0); Data[data. Length-1] = t; } public T This[int index] {get {return data[index];} set {Data[index] = value;} }} public static class Schema {public delegate bool Condtion<t> (T T); public static mylist<t> search<t> (this mylist<t> MyList, condtion<t> condtion) { mylist<t> result = new mylist<t> (); for (int i = 0; i < Mylist.count; i++) {if (condtion (Mylist[i])) {result. ADD (Mylist[i]); }} return result; }} class Program {static void Main (string[] args) {mylist<user> US = new MyList <User> (); for (int i = 1; i <=; i++) {us. ADD (New User () {UserID = i, UserName = "name" + I, age = i}); } var result = us. Search<user> (Delegate (User u) {return u.age > 80;}); Console.ReadLine (); } }
C # Learning Notes