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类的内置方法,用于检查字符串是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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/545433.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

消息队列终极解决方案——Stream(上)

在 Redis 5.0 Stream 没出来之前,消息队列的实现方式都有着各自的缺陷,例如: 发布订阅模式 PubSub,不能持久化也就无法可靠的保存消息,并且对于离线重连的客户端不能读取历史消息的缺陷;列表实现消息队列的方式不能重复消费,一个消息消费完就会被删除;有序集合消息队列…

《算法导论》学习笔记——快速排序

快速排序 1.快速排序原理 快速排序是一种应用很广泛的排序算法,与归并排序类似,快速排序也采用了分治策略。对于一个待排序的数组A[p...r]进行快速排序,根据分治思想,可以分为如下三个步骤:   - 分解:数组…

JavaTCP连接

输入输出操作 可以这样理解: BufferedReader/BufferedWriter使用三部曲: 服务器操作 import java.io.*; import java.net.ServerSocket; import java.net.Socket;public class Server {private static int port 8002;//设置端口号public static v…

JavaScript中的If和Else语句(香草)

Generally if statements have the following syntax: 通常, if语句具有以下语法: if(condition){Our code;}The condition, here can be anything from the mathematical expression, Boolean, relation operations etc. 条件,这里可以是数…

不创建 sequence 自增字段

drop table t_log;create table t_log (log_id number primary key,user_name varchar2(100),log_date date);--新建一个表,有id 用户名 和 日期字段create or replace trigger tri_logonafter logon on databasebegininsert into t_log values(nvl((select max(…

完整案例:实现延迟队列的两种方法

延迟队列是指把当前要做的事情,往后推迟一段时间再做。 延迟队列在实际工作中和面试中都比较常见,它的实现方式有很多种,然而每种实现方式也都有它的优缺点,接下来我们来看。 延迟队列的使用场景 延迟队列的常见使用场景有以下几种: 超过 30 分钟未支付的订单,将会被取…

Java API概述及应用

Java API概述及应用5.1_Scanner和Random的使用(1)Scanner(2)Random生成随机数5.2_ArrayList集合的使用(1)ArrayList的定义及限制(2)函数调用(3)字符串字符串加…

定位position详解:relative与absolute

定位标签:position 包含属性:relative(相对) absolute(绝对) 1.position:relative; 如果对一个元素进行相对定位,首先它将出现在它所在的位置上。然后通过设置垂直或水平位置,让这个…

实战:布隆过滤器安装与使用及原理分析

我们前面有讲到过 HyperLogLog 可以用来做基数统计,但它没提供判断一个值是否存在的查询方法,那我们如何才能查询一个值是否存在于海量数据之中呢? 如果使用传统的方式,例如 SQL 中的传统查询,因为数据量太多,查询效率又低有占用系统的资源,因此我们需要一个优秀的算法…

转:RMAN 备份与恢复 实例

转载自:http://blog.csdn.net/tianlesoftware/article/details/4699320 1. 检查数据库模式: sqlplus /nolog conn /as sysdba archive log list (查看数据库是否处于归档模式中) 若为非归档,则修改数据库归档模式。 startup mount alter…

有重复数字的组合问题_带数字重复的组合和问题

有重复数字的组合问题Description: 描述: This is a standard interview problem to make some combination of the numbers whose sum equals to a given number using backtracking. 这是一个标准的面试问题,它使用回溯功能将总和等于给定数字的数字进…

第四章语法分析和语法分析程序

第四章语法分析和语法分析程序4.1_自顶向下的语法分析4.1.1_自顶向下分析过程的基本特点①消除文法直接左递归②回溯的消除及LL(1)文法4.1.2_递归下降法4.1.3_预测分析法(也叫LL1法,注意分析过程中非终结符号逆序入栈)4.2_自底向上的语法分析…

实战:RediSearch 高性能的全文搜索引擎

RediSearch 是一个高性能的全文搜索引擎,它可以作为一个 Redis Module(扩展模块)运行在 Redis 服务器上。 RediSearch 主要特性如下: 基于文档的多个字段全文索引高性能增量索引文档排序(由用户在索引时手动提供)在子查询之间使用 AND 或 NOT 操作符的复杂布尔查询可选的…

智能优化算法应用:基于法医调查算法3D无线传感器网络(WSN)覆盖优化 - 附代码

智能优化算法应用:基于法医调查算法3D无线传感器网络(WSN)覆盖优化 - 附代码 文章目录 智能优化算法应用:基于法医调查算法3D无线传感器网络(WSN)覆盖优化 - 附代码1.无线传感网络节点模型2.覆盖数学模型及分析3.法医调查算法4.实验参数设定5.算法结果6.…

转:Oracle物理文件

转载:http://www.worlduc.com/blog2012.aspx?bid19969111 -------------------初始化参数文件--------------------------------------------- 在9i之前,参数文件只有一种,它是文本格式的,称为pfile,在9i及以后的版本…

c语言两个浮点数相加_C语言中两个浮点数或双精度数的模数

c语言两个浮点数相加As we know that modules also known as the remainder of the two numbers can be found using the modulus (%) operator which is an arithmetic operator in C/C. The modules operator works with integer values i.e. modulus operator is used to fi…

java线程的5个使用技巧

Java线程的5个使用技巧 Published: 21 Jan 2015 Category: java Java线程有哪些不太为人所知的技巧与用法? 萝卜白菜各有所爱。像我就喜欢Java。学无止境,这也是我喜欢它的一个原因。日常工作中你所用到的工具,通常都有些你从来没有了解过的东…

算法复习第五章贪心法

算法复习第五章贪心法概述TSP最近邻点策略最短连接策略图着色问题最小生成树(Prim算法、Kruskal)0-1bag问题活动安排问题多机调度概述 TSP 最近邻点策略 最短连接策略 图着色问题 最小生成树(Prim算法、Kruskal) 0-1bag问题 活动…

实战:定时任务案例

我在开发的时候曾经遇到了这样一个问题,产品要求给每个在线预约看病的患者,距离预约时间的前一天发送一条提醒推送,以防止患者错过看病的时间。这个时候就要求我们给每个人设置一个定时任务,用前面文章说的延迟队列也可以实现,但延迟队列的实现方式需要开启一个无限循环任…

c语言putchar函数_C语言中的putchar()函数与示例

c语言putchar函数C语言中的putchar()函数 (putchar() function in C) The putchar() function is defined in the <stdio.h> header file. putchar()函数在<stdio.h>头文件中定义。 Prototype: 原型&#xff1a; int putchar(const char *string);Parameters: co…