Expando Object in C# 4.0

We all know Anonymous Types are supported in C# 3.0.It had some limitations such as being the encapsulated properties are read-only.

But ExpandoObject ("Expanded Object" in my words) isnt limited for read-only like Anonymous Types.

In ExpandoObject you can dynamically add properties just by assigning to them

For example:

In Anonymous Types we could code like this:


var Person = new
{
     Name = "Ibrahim Ersoy",
     Age = "25",
     Family = "Ersoys"
};

Console.WriteLine(Person.Name);
Console.WriteLine(Person.Age);
Console.WriteLine(Person.Family);


in ExpandoObject we will be using:

dynamic Person = new ExpandoObject();
Person.name = "Ibrahim";
Person.Age = 25;
Person.Family = "Ersoys";
Console.WriteLine(Person.name);
Console.WriteLine(Person.Age);
Console.WriteLine(Person.Family);



You can access Person in anywhere you want because its read-write ;)