Questions tagged [collection-initializer]

Collection Initializer is a C# syntactic sugar for compact declaration of collection objects with items.

is a syntactic sugar for compact declaration of collection objects with items.

Collection initializers can be used with types which implement interface and have applicable Add method. Collection initializers are described in §7.6.10.3 of C# Language Specification

48 questions
-1
votes
1 answer

Initialize array with a mix of with hard-coded and generated values

This code which initializes an array with two hard-coded values is working perfectly fine: var db = new GoogleGraph { cols = new ColInfo[] { new ColInfo { id = "", label = "Date", pattern ="", type = "string" }, new ColInfo { id…
Seehyung Lee
  • 590
  • 1
  • 15
  • 32
-2
votes
1 answer

function/method in a collection initializer c#

can i insert a method/function in a collection initializer? i am trying to insert expression in the function within a collection initializer but the variable in the class is asking for the declaration of it's body. Thank you. List
larca
  • 9
  • 2
  • 7
-2
votes
1 answer

Declaring a Dictionary> with Functions already inside them c#

First of all, I don't even know what to use when passing on 4 parameters but no return value, I'll just use Func as an example. I do not want to use Dictionary.Add to insert my function, I want it to be inside while initializing the…
Nils
  • 5
  • 1
1 2 3
4