New functions and applications of c#4.0 language (1)

Source: Internet
Author: User

1. Anonymous type (can be used to encapsulate a set of read-only properties into a single object without having to explicitly define a type first)

?
varv = new { Amount = 108, Message = "Hello"};Console.WriteLine(v.Amount);Console.WriteLine(v.Message);

2. Automatic attributes (use automatic attributes no longer create local variables and accessors as in the past, you can simplify the code)

?
publi C class book {      public string bookname { get ; set ;}      public string IBSN { get set ;}

3, anonymous delegate (do not create a new method to create a delegate)

?
List<string> list = new List<string>(new string[] { "str1", "str2" });string fstr = list.Find(    delegate(string str)    {        return str == "str1";     });

3. Lambda expression (simplifies the way anonymous delegates are written)

?
List<string> list = newList<string>(new string[] { "str1", "str2" });stringfstr = list.Find(str => str == "str1");

New functions and applications of c#4.0 language (1)

Related Article

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.