StringIsNullOrEmpty 方法

 

指示指定的字符串是 null 还是  Empty 字符串。

命名空间:  System 程序集: mscorlib(mscorlib.dll 中)
下面的示例将检查三个字符串,并确定是否每个字符串的值、 空字符串,或者是否是 null
using System; 
 
class Sample  
{ 
    public static void Main()  
    { 
    string s1 = "abcd"; 
    string s2 = ""; 
    string s3 = null; 
 
    Console.WriteLine("String s1 {0}.", Test(s1)); 
    Console.WriteLine("String s2 {0}.", Test(s2)); 
    Console.WriteLine("String s3 {0}.", Test(s3)); 
    } 
 
    public static String Test(string s) 
    { 
    if (String.IsNullOrEmpty(s))  
        return "is null or empty"; 
    else 
        return String.Format("(\"{0}\") is neither null nor empty", s); 
    } 
} 
// The example displays the following output: 
//       String s1 ("abcd") is neither null nor empty. 
//       String s2 is null or empty. 
//       String s3 is null or empty.

引文:https://technet.microsoft.com/zh-cn/system.string.isnullorempty

 
posted @ 2016-08-04 21:06  一枚水  阅读(1905)  评论(0)    收藏  举报