close
class ListInit { static void Main(string[] args) { // The demo of List Initialize Set including old declaration and new declaration(C#3.0) // Old initialization. List stringOld = new List(); stringOld.Add("string_1"); stringOld.Add("string_2"); // New initialization. List stringNew = new List() { "string_1", "string_2" }; // Combine Object and List Init. List list = new List{ new Contact{ LastName = "Alen", DateOfBirth = new DateTime(1234,1,13) }, new Contact{ LastName = "AlenTwo", DateOfBirth = new DateTime(2345,1,23) } }; } private class Contact { public string LastName { get; set; } public DateTime DateOfBirth { get; set; } } }
全站熱搜