Phil Haack recently posted a blog entry on duck typing. Read it here. It gives a very good explanation of it and some of its advantages.
He also gives a very good example of a use for duck typing using my library. His example demonstrates a feature that I like to call variance in class members. Specifically, when duck casting an object to an interface, the object need not even implement the interface exactly. Rather, its members may differ from those defined in the interface as long as the parameter types, return types, property types, and event delegate types are convertible to one another, which may be so via duck typing, as in his example. Here is an excerpt from his example: (comments mine)
public interface IHttpContext
{
IHttpRequest Request { get;}
}
public interface IHttpRequest
{
Uri Url { get;}
}
In his example, the sealed class HttpContext is duck casted to IHttpContext. Here is what some of the code might look like for this class for the sake of demonstration:
public sealed class HttpContext
{
public HttpRequest Request { get { ... } }
...
}