---method of class extension:

Source: Internet
Author: User

1 extension methods for the class:2 3 1. Requirements are static classes4 2the method required to write is a static method. 5 3to use the This keyword, the object that is passed in represents the current object. 6 7 Example: The Where method of the extended list collection compares the size of the string. 8     1. Create a class that is named ListExt.cs9     Ten     //1> Creating a static class One      Public StaticClass ListExt A     { -         //Create a static method: Note Use the This keyword.  -          Public Staticlist<string> Mywhere ( Thislist<string> list,func<string,BOOL>mylistext) the         { -         //iterates through the current list combination, invokes the delegate mylistext to pass in a string, returns a bool type -list<string> strlist=Newlist<string>(); -             foreach(varIteminchlist) +             { -                 if(Mylistext (item)) +                 { A Strlist.add (item); at                 } -             } -             returnstrlist; -         } -     } -  in Call the method:  -list<string> newlist=Newlist<string>(); tolist<string> Result=newlist.mywhere (A=>a.compareto ("6") >0);

---method of class extension:

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.