Skip to content

C# Feature – dynamic

dynamic defers member binding to runtime, useful for interop or meta-programming, at the cost of type safety.

C# 4 (2010)

object x = GetComObject();
// Reflection or explicit casts required
dynamic x = GetComObject();
x.Save(); // resolved at runtime
dynamic json = System.Text.Json.JsonSerializer.Deserialize<dynamic>("{\"a\":1}");
Console.WriteLine(json.a);
  • Avoid in core domain logic; prefer static types.
  • Exceptions surface at runtime if members are missing.
  • Interacts with nullable contexts; prefer static typing where feasible.