C# Feature β dynamic
Overview
Section titled βOverviewβdynamic defers member binding to runtime, useful for interop or meta-programming, at the cost of type safety.
Introduced In
Section titled βIntroduced InβC# 4 (2010)
object x = GetComObject();// Reflection or explicit casts requireddynamic x = GetComObject();x.Save(); // resolved at runtimeAnnotated Example
Section titled βAnnotated Exampleβdynamic json = System.Text.Json.JsonSerializer.Deserialize<dynamic>("{\"a\":1}");Console.WriteLine(json.a);Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Avoid in core domain logic; prefer static types.
- Exceptions surface at runtime if members are missing.
Related Features
Section titled βRelated FeaturesβVersion Notes
Section titled βVersion Notesβ- Interacts with nullable contexts; prefer static typing where feasible.