为string类型,加一个扩展方法,IsNullOrEmpty,事实上.net已经把这个扩展方法集成了
还可以设计一个过滤Email的扩展方法
class Program
{
    static void Main(string[] args)
    {
        string newString = null;
        if (newString.IsNullOrEmpty())
        {
            // Do Something
        }
    }
}
public static class Extensions
{
 
    public static bool IsNullOrEmpty(this string s)
    {
        return (s == null || s.Trim().Length == 0);
    }
public static bool
        IsValidEmailAddress(this string s)
    {
        Regex regex = new
          Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$");
        return regex.IsMatch(s);
    }
}

相关文章:

  • 2021-11-29
  • 2021-05-22
  • 2021-07-16
  • 2021-08-20
  • 2022-12-23
  • 2021-06-18
  • 2021-06-17
猜你喜欢
  • 2021-10-18
  • 2022-12-23
  • 2021-06-01
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案