C#教程
C#控制语句
C#函数
C#数组
C#面向对象
C#命名空间和异常
C#文件IO
C#集合
C#多线程
C#其它

C# String IsNullOrWhiteSpace()

C# String IsNullOrWhiteSpace()

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

Signature

public static bool IsNullOrWhiteSpace(String str)

参数

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

返回

返回布尔值。

C# String IsNullOrWhiteSpace() 方法示例

using 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
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4