tags:

views:

26

answers:

1

What is the terminology for the usage of "new" in:

 list.Add(new{a=1, b=2})

And what type should I replace the T in List getList if I want to use the list as the returned value? I don't want to replace T with "object" because I want to parse it in Linq query.

Thanks.

+1  A: 

Since you did not specify a type: new {1), it's called object initializers with anonymous types. (MSDN Explaining them) The Object Initializer part is where you do { a=1, b=2}.

If you want to be able to reference a type, you will have to create a type and stuff the values in.

list.Add(
  new MyType() {
         a=1, 
         b=2 
 }); 

If you are just going to be pairing two items look into using the Pair Class. There is also a Triplet Class just in case you might want to store 3 items.

Nix