Since I never noticed these two methods and I kept using them. When I saw them, I only noticed them when I was often used in projects developed by Microsoft. I checked MSDN and remembered them to avoid forgetting them in the future.
Everyone knows that this function is to determine whether the string is: null or. If it is a character like "\t", it will return false. In order to determine the filtering function, you need to use the Trim() and Length attributes to help determine whether the length is zero, so the following method is produced.
This is to judge all whitespace characters, the function is equivalent to the sum of the sum ().Length, and it will be correct to give the string to any character that is ture. According to the instructions of MSDN, this method will have higher performance and conciseness than calling the above two methods, so it is recommended to use it when judging this function.
using System; public class Example { public static void Main() { string[] values = { null, String.Empty, "ABCDE", new String(' ', 20), " \t ", new String('\u2000', 10) }; foreach (string value in values) Console.WriteLine(String.IsNullOrWhiteSpace(value)); } } // The example displays the following output: // True // True // False // True // True // True
The above is the code execution effect. As for performance, let’s listen to Microsoft. However, compared with that, the previous one must have higher performance [has not tested it. If anyone has tested it, please leave a message to tell me, thank you! 】, so you still need to use it selectively.