C#中使用this为类添加方法

public static bool IsNullOrCountLTE0(this DataTable dt)
        {
            if (dt == null || dt.Rows.Count <= 0) return true;
            return false;
        }
public static bool IsNullOrEmpty(this string str)
        {
          
            if (string.IsNullOrEmpty(str)) return true;
            return false;
        }

则可以如下使用:

DataTalbe dt=new DataTable();

dt.IsNullOrCountLTE0();

string str=”“;

str.IsNullOrEmpty();

原文地址:https://www.cnblogs.com/fhuafeng/p/3003967.html