日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

String.IsNullOrEmpty()方法以及C#中的示例

發(fā)布時(shí)間:2025/3/11 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 String.IsNullOrEmpty()方法以及C#中的示例 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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:TrueTrueFalse

C#使用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 False

Example 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)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。