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类的内置方法,用于检查字符串是Null还是Empty ? 如果未使用正确的值初始化字符串对象,则将其视为“空字符串” ;如果已初始化字符串对象但不包含任何值,即为该字符串对象分配了值( “” ),则将其视为“空字符串”

Syntax:

句法:

    public static bool IsNullOrEmpty(String str);

The method is called with "string"/ "String". Here, "string" is an alias of "String" class.

用“字符串” /“字符串”调用该方法。 此处,“字符串”是“字符串”类的别名。

Parameter(s):

参数:

  • str – represents a string value or string object to be checked.

    str –表示要检查的字符串值或字符串对象。

Return value:

返回值:

  • bool – it returns "True" if str is null or empty, otherwise it returns "False".

    bool-如果str为null或为空,则返回“ True”,否则返回“ False”。

Example:

例:

    Input:
string str1 = "";
string str2 = null;
string str3 = "IncludeHelp";
Function call
Console.WriteLine(string.IsNullOrEmpty(str1));
Console.WriteLine(string.IsNullOrEmpty(str2));
Console.WriteLine(string.IsNullOrEmpty(str3));
Output:
True
True
False

C#使用String.IsNullOrEmpty()方法将字符串转换为字符数组的示例 (C# Example to convert string to characters array using String.IsNullOrEmpty() method)

Example 1:

范例1:

using System;
class IncludeHelp
{static void Main()
{// declaring string variables
string str1 = "";
string str2 = null;
string str3 = "IncludeHelp";
// check whether string is empty/null or not
Console.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 variable
string str = "IncludeHelp";
// checking whether string is null/empty or not
if(string.IsNullOrEmpty(str))
Console.WriteLine("str is empty or null");
else
Console.WriteLine("str is not empty or null");
//now assigning null to the string
str = null;
// checking whether string is null/empty or not
if(string.IsNullOrEmpty(str))
Console.WriteLine("str is empty or null");
else
Console.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

String.IsNullOrEmpty()方法以及C#中的示例相关推荐

  1. find 命令示例_数组find()方法以及JavaScript中的示例

    find 命令示例 JavaScript find()方法 (JavaScript find() method) find() method is used to get the first elem ...

  2. parse 日期_日期parse()方法以及JavaScript中的示例

    parse 日期 JavaScript Date parse()方法 (JavaScript Date parse() method) parse() method is a Date class m ...

  3. matlab中now函数_now()方法以及JavaScript中的示例

    matlab中now函数 JavaScript now()方法 (JavaScript now() method) now() method is a Date class method, it is ...

  4. as_hash ruby_Hash.merge(other_hash)方法与Ruby中的示例

    as_hash ruby Hash.merge(other_hash)方法 (Hash.merge(other_hash) Method) In this article, we will study ...

  5. 日期setMinutes()方法以及JavaScript中的示例

    JavaScript日期setMinutes()方法 (JavaScript Date setMinutes() method) setMinutes() method is a Date class ...

  6. 数组的fill方法_数组fill()方法以及JavaScript中的示例

    数组的fill方法 JavaScript fill()方法 (JavaScript fill() method) fill() method is used fill the array with a ...

  7. 数组中的reverse_数组reverse()方法以及JavaScript中的示例

    数组中的reverse JavaScript reverse()方法 (JavaScript reverse() method) reverse() method is used to reverse ...

  8. 数组copyWithin()方法以及JavaScript中的示例

    JavaScript copyWithin()方法 (JavaScript copyWithin() method) copyWithin() method is used to copy the s ...

  9. android使用post方法登录,使用REST API使用POST方法在Android中登录示例

    如果您熟悉库,则完成此任务的简单方法是使用库.我推荐 Ion,因为它小而且易于使用.添加库并将以下代码段添加到您选择的方法中. Ion.with(getApplicationContext()) .l ...

  10. html ol中reverset,List T .Reverse()方法以及C#中的示例

    C#List .Reverse()方法 列表.Reverse()方法用于反转所有列表元素. 语法: void List.Reverse(); 参数:不接受任何内容. 返回值:不返回任何内容–返回的类型 ...

最新文章

  1. 一块V100运行上千个智能体、数千个环境,这个「曲率引擎」框架实现RL百倍提速...
  2. 【具体使用实例】Rall封装线程(C\C++)
  3. 迪米特法则(Law of Demeter) 简介
  4. CF755G PolandBall and Many Other Balls(多项式/倍增fft)
  5. PoE交换机不供电了该怎么办?
  6. ASP.NET中Session模型简介
  7. 利用iTextSharp组件给PDF文档添加图片水印,文字水印
  8. Java基础类冒泡排序_Java基础 -- 冒泡排序算法(带详细注释)
  9. macOS Big Sur系统Parallels Desktop无法启动的解决办法
  10. android ViewFlipper的使用
  11. 操作系统实验 文件复制/复制文件
  12. 线性代数辅导讲义(第四章 线性方程组)
  13. 维多利亚计算机研究生,2020年惠灵顿维多利亚大学计算机信息硕士申请条件
  14. HTTP协议以及返回状态码
  15. Widows 和Linux 查看端口和杀掉进程的方法
  16. 镁客网每周硬科技领域投融资汇总(3.24-3.30),FF喜提新救主...
  17. 平安居家养老服务上市
  18. Vue的渲染函数renderh
  19. 独家 | 机器学习基础知识梳理,新手必备!(附链接)
  20. Thymeleaf th:include、th:replace使用

热门文章

  1. html json to table,javascript - HTML - Convert json to table - Stack Overflow
  2. 项目管理最佳实践方法_项目管理最佳实践,企业如何进行有效的项目管理
  3. 获取Linux内存、cpu、磁盘IO等信息
  4. 找出占用cpu最高的线程
  5. 1439: 2.4.5 Fractions to Decimals 分数化小数
  6. WPF Image Source 设置相对路径图片
  7. 基于微服务架构,改造企业核心系统之实践
  8. 几种开源软件授权协议
  9. 两个精彩的比喻:吞吐量和延迟、信号量和互斥锁
  10. MathCAD求解方程组