A preliminary study on new features of C # 3.0 PART5: Anonymous type

Source: Internet
Author: User
Tags anonymous new features

Anonymous type (anonymouse type)--What multiple systems are anonymous these days:
a mechanism for automatically generating types based on initialization lists at initialization time.

Typical code:
1class Program
2    {
3        static void Main (string[] args)
4        {
5             var x = new {a = 3, B = 5, c = "some text"};
6            Console.WriteLine (x.a.ToString ());
7       }
8   } very strange ~ ~ ~
Do not think that this var x is really no type, in fact, this is a compiler magic,
when we compile this code, the compiler will automatically produce the following types of definitions:
  1class __anonymous1
 2{
 3    private int _a = 3;
 4    private int _b = 5;
 5    private String _c = "some text";
 6
 7    public int a {get {return _a;} set {_a = value;}}
 8    public int B {get {_b;} set {_b = value;}}
 9    public int C {get {_c;}set {_c = value;}}
10}
One
This does not have to be initialized with my previous Var, and must let the compiler "guess" the correct type of this sentence is contradictory.
PS: In another 20 years, the compiler will be able to do anything, or industry experts, "boss, buy a compiler for the telecommunications industry, with SP value-added services expansion Package"







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.