In C#4.0, we have the concept of dynamic, but how to create a dynamic object from a static static object?
Below code will generate exception at run time. The dynamic object is from C# class, but it could be object from other languages through Dynamic Language Runtime (DLR). The point is not how to invoke static method, but how to invoke static method of dynamic object which could not be created in C# code.
class Foo
{
public static int Sum(int x, int y)
{
return x + y;
}
}
class Program
{
static void Main(string[] args)
{
dynamic d = new Foo();
Console.WriteLine(d.Sum(1, 3));
}
}
dynamic type is invented as bridge between C# and other programming language. There is some other language (e.g. Java) allows to invoke static method through object instead of type.
for more details please visit
enter link description here
ais a static property or member variable of some other class? If so, write a clone method in classAthat returns a deep clone of typeAand assign it to anything you want to assign it to. All that the modifierstaticon a property or member variable means is that the property / member variable belongs to the class, not to an instance of the class. Other than that, the object referenced by that property/member variable is just an object.