dynamic Type
Question
Describe the
dynamictype. How does it differ from an anonymous type, and can one dynamic variable hold different data types?
Short interview answer
dynamicdefers member binding and type checks to runtime. An anonymous type is compiler-generated, strongly typed, and has a fixed shape. Adynamicvariable can be assigned values of different runtime types, but invalid operations fail at runtime.
Detailed answer
dynamic is useful mainly for COM interop, dynamic-language integration, or genuinely dynamic object models. The compiler does not validate the member call, so a missing member or wrong arguments produce a runtime binder failure. An anonymous type is not dynamic: its members are inferred at compile time and cannot be changed after creation.