为system对象添加扩展方法

Posted fang_beny

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为system对象添加扩展方法相关的知识,希望对你有一定的参考价值。

 ////扩展方法类:必须为非嵌套,非泛型的静态类
        public static class DatetimeEx
        {
            //通过this声明扩展的类,这里给DateTime类扩展一个Show方法,只有一个参数
            public static void Show(this DateTime date, string msg)
            {
                Console.WriteLine("扩展方法调用");
                Console.WriteLine(msg);
            }
        }

  

以上是关于为system对象添加扩展方法的主要内容,如果未能解决你的问题,请参考以下文章