Skip to content

Anonymous Types vs. dynamic

Question

Explain the difference between anonymous and dynamic types.

Short interview answer

An anonymous type has a compiler-generated, fixed shape checked at compile time. dynamic defers member binding to runtime and may fail only when an operation executes.

Detailed answer

Anonymous types are useful for local projections, such as a LINQ select new { Name, Total }. The compiler knows their members within the scope where the inferred type is available. dynamic is for runtime-discovered members and should be limited to interoperability or truly dynamic data.

Sources