Anonymous Generics - Where Can I Use This?

I recently discovered a trick using an example listing to create an instance with an anonymous type.

http://brendanjerwin.com/blog/2009/03/19/anonymous-generics/

So, its a neat trick, but when will it be used? Any ideas?

+4
source share
1 answer

The main place I use is to create a container for anonymous types.

public static List<T> CreateListOfAnonymous<T>(T unused) { return new List<T>(); } 

Using:

 public void Foo() { var list = CreateListOfAnonymous(new { Name = String.Empty, Age = 42 }); list.Add(new { Name = "foo", Age = 28 }); } 
+5
source

All Articles