Anonymous objects for the LINQ topic

Source: Internet
Author: User

An anonymous object is a new mechanism for c#3.0, which uses the new keyword and an initializer for an object to create an anonymous object. As the name implies, this object is an anonymous type object when created, with no specific type. When it comes to anonymous objects, the var keyword we talked about earlier comes in handy. Because you do not know the exact type of the object, you can only declare an object with Var.

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Linq;6 7 namespaceLinqdemo8 {9     class ProgramTen     { One         Static voidMain (string[] args) A         { -  -             varStudent =New{userid=001, username="it teenager", age= -, classname="it from getting started to giving up"}; the  -Console.WriteLine (student.userid+":"+student.username); -  - Console.readkey (); +         } -  +         A     } at  -      -}


Look at the results of the operation:

Our compiler first creates a class for the new object, the class name is determined by the compiler, specifies the appropriate property in the class, and then uses that class to create an object.

Anonymous objects for the LINQ topic

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.