Perficient Interview Question

Tell me about C# object and collection initializers.

Interview Answer

Anonymous

Jun 17, 2015

Simple So lets say you want to create a list of integers List ListOfIntegers = new List(); now instead of adding one value at a time, for eg ListOfIntegers.Add(1); ListOfIntegers.Add(2); we can initialize the value using the collection initializer. List ListOfIntegers = new List(){1,2,3,4,5,6,7,8,9};