IsNullOrEmpty和IsNullOrWhiteSpace的区别
IsNullOrEmpty:判断字符串是否为null还是string.Empty
IsNullOrWhiteSpace:判断字符串是否为null还是string.Empty还是由空白字符组成的
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace IsNullOrWhiteSpace { class Program { static void Main(string[] args) { string[] array = new string[] { "", " ", null, string.Empty, }; Console.WriteLine("IsNullOrWhiteSpace:"); foreach (var item in array) { Console.WriteLine(string.IsNullOrWhiteSpace(item).ToString()); } Console.WriteLine("\r\t"); Console.WriteLine("IsNullOrEmpty:"); foreach (var item in array) { Console.WriteLine(string.IsNullOrEmpty(item).ToString()); } Console.ReadKey(); } } }


浙公网安备 33010602011771号