String.IsNullOrEmpty()方法以及C#中的示例
C#String.IsNullOrEmpty()方法 (C# String.IsNullOrEmpty() Method)
String.IsNullOrEmpty() method is a built-in method of String class and it is used to check whether a string is Null or Empty? If string object is not initialized with a correct value it will be considered as "null string", if string object is initialized but contains nothing i.e. it is assigned the value ("") it will be considered as "empty string".
String.IsNullOrEmpty()方法是String類的內(nèi)置方法,用于檢查字符串是Null還是Empty ? 如果未使用正確的值初始化字符串對(duì)象,則將其視為“空字符串” ;如果已初始化字符串對(duì)象但不包含任何值,即為該字符串對(duì)象分配了值( “” ),則將其視為“空字符串” 。
Syntax:
句法:
public static bool IsNullOrEmpty(String str);The method is called with "string"/ "String". Here, "string" is an alias of "String" class.
用“字符串” /“字符串”調(diào)用該方法。 此處,“字符串”是“字符串”類的別名。
Parameter(s):
參數(shù):
str – represents a string value or string object to be checked.
str –表示要檢查的字符串值或字符串對(duì)象。
Return value:
返回值:
bool – it returns "True" if str is null or empty, otherwise it returns "False".
bool-如果str為null或?yàn)榭?#xff0c;則返回“ True”,否則返回“ False”。
Example:
例:
Input:string str1 = "";string str2 = null;string str3 = "IncludeHelp";Function callConsole.WriteLine(string.IsNullOrEmpty(str1));Console.WriteLine(string.IsNullOrEmpty(str2));Console.WriteLine(string.IsNullOrEmpty(str3));Output:TrueTrueFalseC#使用String.IsNullOrEmpty()方法將字符串轉(zhuǎn)換為字符數(shù)組的示例 (C# Example to convert string to characters array using String.IsNullOrEmpty() method)
Example 1:
范例1:
using System; class IncludeHelp {static void Main(){// declaring string variablesstring str1 = "";string str2 = null;string str3 = "IncludeHelp";// check whether string is empty/null or notConsole.WriteLine(string.IsNullOrEmpty(str1));Console.WriteLine(string.IsNullOrEmpty(str2));Console.WriteLine(string.IsNullOrEmpty(str3));} }Output
輸出量
True True FalseExample 2:
范例2:
using System;class IncludeHelp {static void Main(){// declaring string variablestring str = "IncludeHelp";// checking whether string is null/empty or notif(string.IsNullOrEmpty(str))Console.WriteLine("str is empty or null");elseConsole.WriteLine("str is not empty or null");//now assigning null to the stringstr = null;// checking whether string is null/empty or notif(string.IsNullOrEmpty(str))Console.WriteLine("str is empty or null");elseConsole.WriteLine("str is not empty or null");} }Output
輸出量
str is not empty or null str is empty or null翻譯自: https://www.includehelp.com/dot-net/string-isnullorempty-method-with-example-in-csharp.aspx
總結(jié)
以上是生活随笔為你收集整理的String.IsNullOrEmpty()方法以及C#中的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: parse 日期_日期parse()方法
- 下一篇: --c语言运算符_C按位运算符-能力问题