Dynamic Typing

Starting with .NET 4.0, C# supports dynamic typing. Variables typed as dynamic are used in a late-bound fashion, meaning that operations applied to them are resolved at runtime rather than at compile time. This is useful when dealing with an object that cannot be typed statically in a comfortable manner. Samples include Extensible Markup Language (XML) documents without an XML Schema Definition (XSD) schema or objects from dynamic languages such as Python, Ruby, or JavaScript.

Other than the built-in types discussed so far, no direct mapping exists between the C# reserved word dynamic and an underlying BCL type. Instead, dynamic is a special alias for System.Object, but with some additional metadata sprinkled on top of it to tell ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.