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 @ 2020-11-21 16:34  MaxBruce  阅读(135)  评论(0)    收藏  举报