Dynamic Types and ExpandoObject
🌀 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