QQ聊天

C#扩展一个现有的类

做个记录,写个示例

using System;


class Rubbish
{
    public void Say() 
    { 
        Console.Write("Hello"); 
    }
}
static class RubbishExtensions
{
    public static void Say(this Rubbish argRubbish, string argString)
    {
        Console.Write(argString);
    }
}
class Program
{
    static void Main(string[] args)
    {
        Rubbish theRubbish = new Rubbish();
        theRubbish.Say("Hey");
        Console.ReadKey(false);
    }
}

 

posted @ 2014-05-07 12:36  SITT  阅读(760)  评论(0编辑  收藏  举报
QQ聊天