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();
        }
    }
}

 

posted @ 2016-12-14 20:29  花生打代码会头痛  阅读(732)  评论(0)    收藏  举报