Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
C# 4.0 introduces a new type called dynamic. In some ways it looks just like any other type such as int, string, or FileStream: you can use it in variable declarations, or function arguments and return types, as Example 18-4 shows. (The method reads a little oddly—it’s a static method in the sense that it does not relate to any particular object instance. But it’s dynamic in the sense that it uses the dynamic type for its parameters and return value.)
static dynamic AddAnything(dynamic a, dynamic b)
{
dynamic result = a + b;
Console.WriteLine(result);
return result;
} |