當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C# String IsNullOrEmpty()用法及代碼示例

C# IsNullOrEmpty() 方法用於檢查指定的字符串是空字符串還是空字符串。它返回一個布爾值 true 或 false。

簽名

public static bool IsNullOrEmpty(String str)

參數

str:它是一個字符串參數,用於檢查字符串。

返回

它返回布爾值。

C# 字符串 IsNullOrEmpty() 方法示例

using System; 
    public class StringExample  
    {  
        public static void Main(string[] args)  
        {  
           string s1 = "Hello C#";
           string s2 = "";
           bool b1 = string.IsNullOrEmpty(s1);
           bool b2 = string.IsNullOrEmpty(s2);
           Console.WriteLine(b1);
           Console.WriteLine(b2);
         }  
    }

輸出:

False
True




相關用法


注:本文由純淨天空篩選整理自 C# String IsNullOrEmpty()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。