C # is statically typed, so regular classes must be declared before using them. However, anonymous types allow you to declare classes based on initialization. After the declaration, neither the type nor the instance may be changed.
For a more dynamic approach, take a look at ExpandoObject , which allows you to dynamically add properties. This requires C # 4, and the link must be declared dynamic.
dynamic car = new ExpandoObject(); car.Color = "Black"; car.Type "Sports";
source share