Dynamic Types and ExpandoObject

Advanced Updated November 16, 2024

🌀 3. Dynamic Programming in C#

C# supports dynamic typing via the dynamic keyword and the ExpandoObject.

🔸 Using dynamic

dynamic obj = "hello";
Console.WriteLine(obj.Length); // Runtime-bound

🔸 ExpandoObject

dynamic person = new ExpandoObject();
person.Name = "Alice";
person.Speak = (Action)(() => Console.WriteLine("Hi"));
person.Speak();  // Output: Hi