[. Net Study Notes] C # new features-Anonymous type

Source: Internet
Author: User

For the anonymous type, I am a little lazy and can reprint it directly.Article: Http://blog.csdn.net/zlghitler/article/details/1706093

Anonymous type
C #2.0 introduced the anonymous method, and C #3.0 introduced the anonymous type. The anonymous type is similar to the anonymous method. They are both built in the embedded mode and do not have a formal name. To create an anonymous type, you must combine the above two concepts: Object initializer and hidden local variables. The following is an example of an anonymous type:

Varmytype = New {Length = 79 , Width = 30  };  //  The range of the anonymous type is the same as that of any other variables.  //  For example, the followingCodeThe Cobra instance in the block is only valid in the Speed Function Block:  Private   Void Speed (){  VaR Cobra = New {Horsepower = 550 , Torque = 570  };}  //  If an anonymous type is initialized and another anonymous type is in the range domain, and their signatures are the same, the second type occupies the first type.  //  For example, in the following code, Cobra and Mustang are both anonymous and can be set to each other.  Private   Void  Speed (){  VaR Cobra =New {Horsepower = 550 , Torque = 570  };  VaR Mustang = New {Horsepower = 300 , Torque = 300  }; Mustang = Cobra; //  Or you cocould say Cobra = mustang }

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.