I want to find out if there is a way to initialize a List<T> , where T is an object , just as a simple collection is initialized?
Simple collection initializer:
List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Object collection initializer:
List<ChildObject> childObjects = new List<ChildObject> { new ChildObject(){ Name = "Sylvester", Age=8 }, new ChildObject(){ Name = "Whiskers", Age=2 }, new ChildObject(){ Name = "Sasha", Age=14 } };
The question is, how and if you can do something like this?
List<ChildObject> childObjects = new List<ChildObject> { { "Sylvester", 8} , {"Whiskers", 2}, {"Sasha", 14} };
c #
rick schott
source share