Most advisable way of checking empty strings in C#

后端 未结 7 866
抹茶落季
抹茶落季 2020-12-13 01:51

What is the best way for checking empty strings (I\'m not asking about initializing!) in C# when considering code performance?(see code bel

相关标签:
7条回答
  • 2020-12-13 02:45

    Create an extension method for complete check:

    public static bool IsEmpty(this string s)
    {
      if(s == null) return true;
      return string.IsNullOrEmpty(s.Trim()); // originally only (s)
    }
    

    Sorry, not good code, fixed. Now this will tell you, if the string is empty or if is empty after trimming.

    0 讨论(0)
提交回复
热议问题