In this blog post , lets have a look at the usage of ExpandoObject in C# to create the C# objects dynamically.
ExpandoObject was initially introduced in C# 4.0 which was also incidentally part of Dynamic Language Runtime (DLR).
How to build C# objects dynamically ?
In this blog post, let’s look at the usage of ExpandoObject in C# to create the C# objects dynamically.
ExpandoObject was introduced in C# 4.0, which was also incidentally part of Dynamic Language Runtime (DLR).
dynamic expandoObj = new ExpandoObject(); expandoObj.MovieName = "Bigil";
You might have a scenario where you want to create the object and the propertyname has to be dynamic.
For example , imagine that you want the property name MovieName1 , MovieName2 etc .
You can try the below
var expandoObj = new ExpandoObject() as IDictionary<string, Object>; expandoObj.Add("MovieName1", "bigil");