C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# IsNullOrWhiteSpace() 空或空白字符串

C# IsNullOrWhiteSpace() 方法用于检查指定字符串是否为空,或仅包含空白字符。它返回布尔值 True 或 False。

签名

句法 (Syntax)

public static bool IsNullOrWhiteSpace(String str)

范围

str:它是一个字符串参数,用于检查字符串中的空、空白。

返回

它返回布尔值。


C# String IsNullOrWhiteSpace() 方法示例

例子 (Example)

sing System;   
    public class StringExample    
     {    
        public static void Main(string[] args)   
        {    
           string s1 = "Hello C#";  
           string s2 = "";  
           string s3 = " ";  
           bool b1 = string.IsNullOrWhiteSpace(s1);  
           bool b2 = string.IsNullOrWhiteSpace(s2);  
           bool b3 = string.IsNullOrWhiteSpace(s3);  
           Console.WriteLine(b1);       // returns False   
           Console.WriteLine(b2);       // returns True   
           Console.WriteLine(b3);       // returns True   
       }    
    }

输出:

False
True
True


  • 使用社交账号登录,本站支持
全部评论(0)