VaR keyword and Anonymous class (from www. sysoft. CC)

Source: Internet
Author: User

VaR type inference keyword. It can automatically infer the type of the variable after the value assignment, but can only be used for local variables. It cannot be used for class member definitions and parameter passing.
An anonymous class, that is, a class cannot be defined, which is automatically generated by the system. The following Code creates an anonymous real-column SSZ, and the system automatically defines the name, age, height, job and other field members. This definition is similar to the list <t> generic initializer.

Static void main (string [] ARGs) {var SSZ = new {name = "Shi shaozhuang", age = 38, Height = 35, job = ""}; console. writeline (SSZ. name); console. writeline (SSZ. age); console. writeline (SSZ. height); console. writeline (SSZ. job); console. readkey ();

}

VaR keyword and Anonymous class (from www. sysoft. CC)

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.