xiaowei-blog

导航

扩展方法测试

 

 

 

 

 

 

    //定义扩展方法
    //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;         }

    }

 

posted on 2015-02-16 11:01  xiaowei-blog  阅读(116)  评论(0编辑  收藏  举报

欢 迎 大 家光 临 我 的 个 人 博 客 !