为system对象添加扩展方法

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

  

原文地址:https://www.cnblogs.com/fang-beny/p/5267885.html