Search⌘ K
AI Features

The ExpandoObject Class

Explore how to utilize the ExpandoObject class in C# to implement dynamic binding within the .NET framework. This lesson helps you create objects that can expand with new properties and methods during execution, enabling flexible and runtime-defined behavior in your applications.

We'll cover the following...

A key feature of the DLR resides in the System.Dynamic namespace: the ExpandoObject class. This type lets us create dynamic objects that expand during program execution. For instance, we could add a method or some other member at runtime. The System.Dynamic namespace brings JavaScript-like capabilities to .NET.

Syntax

We instantiate the ExpandoObject class using the new keyword. We declare the variable using the dynamic keyword to utilize its runtime capabilities.

Here is a quick example of how we ...