Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0218 Properties and anonymous type

The property of anonymous type is inferred from the expression. using System; class Test { static void Main() { string FirstName = "J"; var person = new { FirstName }; // var person = new {FirstName = "J"}; Console.WriteLine(person.FirstName); } } The output: J