void Main()
{
dynamic foo;
var bar = new { name = "John", title="code monkey"};
var bar2 = new { name = "John", title="junior code monkey"};
foo = bar;
WriteIt( foo);
WriteIt(bar2);
}
static void WriteIt( dynamic dynamo)
{
Console.WriteLine(dynamo.title);
}
One important gotcha with using dynamic typing is that extension methods aren't currently available. That is a real shame since these two techniques would go together naturally for more ruby-esque development. But at some point, if you really want or need to program with dynamic techniques in .NET you are better of with IronRuby or IronPython. Sadly, Microsoft's interest in the DLR appears to have waned after successfully making programming for Microsoft Office easier in .NET. You can perform a cast though, but only if your type is not anonymous.