Sure, basically as of C# 3, everything was statically typed, meaning the compiler knows the type of everything at compile time. This is good because it gives you a safety net when passing different types around; since the compiler knows what properties/methods accept as parameters and return as values it can ensure you are passing the right types.
However, sometimes you have no idea what the type of the thing is. A good example is XML. Most of the time the XML is loosely typed and we have to resort to element.Element("FirstName").Value. Other good examples of things that do not have static type information are: REST services, COM APIs, the HTML DOM, SQL Result Sets (When not using ORM). Also when communicating with a library written in alanguage that does not have static typing (Ruby, Python, JScript, ...)
So it makes sense to have a concept of dynamic in the language for these things that do not have static types. C# introduces this in the form of IDynamicObject. If you implement this interface on a class, that means that you can intercept all calls to the object for method calls, property setters/getters, etc and define logic for them.
Then we could deal with XML in a more natural way:
// xmlElement is statically typed as dynamic
string firstName = xmlElement.FirstName;
Or REST Services:
// restEndpoint is statically typed as dynamic
List<People> = restEndpoint.People.Group("Marketing");
Or SQL Result sets:
// db.Query() returns an IEnumerable of dynamic objects (objects that implement IDynamicObject)
foreach (dynamic person in db.Query("SELECT * FROM People")) {
Console.WriteLine(person.FirstName);
Console.WriteLine(person.LastName);
// ...
}
You should read here for more information:
http://blogs.microsoft.co.il/blogs/shayf/archive/2008/12/19/the-dynamic-keyword-part-1-introduction.aspxhttp://blogs.msdn.com/samng/archive/2008/10/29/dynamic-in-c.aspx