I understood,normally generics is for compile time safe and allow us to keep strongly typed collection.Then how do generic allow us to store anonymous types like
List<object> TestList = new List<object>();
TestList.Add(new { id = 7, Name = "JonSkeet" });
TestList.Add(new { id = 11, Name = "Marc Gravell" });
TestList.Add(new { id = 31, Name = "Jason" });
This works because
objectis the root type of all instances in .Net. Hence anything expression can be used for a location expecting anobjectbecause they all meet the basic contract ofSystem.object.For example the following is completely legal.