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.