HomeCSharpHow to build C# objects dynamically ?

How to build C# objects dynamically ?

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");

Share:

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...