导航

使用dynamic 类型动态调用方法

Posted on 2010-09-03 21:57  AlexCube  阅读(387)  评论(0编辑  收藏  举报

class Program
{
    static void Main(string[] args)
    {
        dynamic d = Activator.CreateInstance(typeof(DemoType));

        object o = d.ToString();

        Console.WriteLine(o);

        Console.WriteLine(d.Value);
    }
}


class DemoType
{
    public override string ToString()
    {
        return "Hello World";
    }


    public int Value
    {
        get
        {
            return 100;
        }
    }
}