C # Learning Notes

Source: Internet
Author: User

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

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.