0
点赞
收藏
分享

微信扫一扫

C#扩展一个现有的类

刘员外__ 2023-06-05 阅读 17

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);
      }
}



举报

相关推荐

0 条评论