c#3.0 an implicitly typed array of new features

Source: Internet
Author: User
Tags anonymous

c#3.0 This feature is an extension of implicitly typed local variables that, with this feature, makes it easier to create arrays. We can declare an array directly using the "new[" keyword, followed by a list of the initial values of the array. Here, we do not specify the type of the array directly, and the type of the array is inferred from the initialization list.

class AnonymousTypeArray : AppRunner.AbstractApplication
{
public override void Run()
{
var intArray = new[] { 1, 2, 3, 4, 5 };
var doubleArray = new[] { 3.14, 1.414 };
var anonymousTypeArray = new[] {
new { Name="van’s", Sex=false, Arg=22 },
new { Name="martin", Sex=true, Arg=23 }
};

Console.WriteLine(intArray);
Console.WriteLine(doubleArray);
Console.WriteLine(anonymousTypeArray[0].Name);
}
}

In the above code, the declaration of a Anonymoustypearray variable uses both an implicitly typed array and an anonymous type, first creating an anonymous type, and then initializing the list of values to infer the exact type of the group.

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.