C# Interview Question #138
What is the ExpandoObject class?
Reflection, Dynamic & Runtime Senior Advanced
Quick Interview Answer
ExpandoObject is a dynamic object whose members can be added and removed at runtime.
Detailed Explanation
ExpandoObject is a dynamic object whose members can be added and removed at runtime.
It implements IDynamicMetaObjectProvider and IDictionary<string,object?>, allowing it to be used through dynamic syntax or dictionary-style access.
ExpandoObject can be useful for flexible data-shaping scenarios, but strongly typed DTOs are normally preferable for public APIs and production business logic because they provide validation, tooling, refactoring support, and compile-time safety.
Code Example
dynamic item = new ExpandoObject();
item.Name = "Laptop";
item.Price = 1200m;
Console.WriteLine(item.Name);