扩展方法测试

    //定义扩展方法
    //1.类类型必须为静态的
    //2. 类名为扩展方法的容器,扩展名是要被扩展的类型名称,既要其中添加方法的类
    //3.this关键字是扩展方法标识,this关键字后面的类型为要扩展的类型
    //4.this变量后面的的变量为参数列表

  static class StringExtension     {      

   // 判断一个字符串是否整数,及正整数    

     public static bool IsInt(this string text, bool positive = false)   

      {             int n;         

    if (int.TryParse(text, out n))      

       {                 if (positive)      

                {               return n > 0;          

            }   

              return true;

            }       

      return false;         }

    }

原文地址:https://www.cnblogs.com/xiaowei-blog/p/4293838.html