空字符串(NULL)是尚未初始化的字符串变量,并且具有空值。
如果我们尝试调用null字符串的任何方法或者属性,则会收到异常。
NULL字符串有价值与代码中定义的任何其他变量完全相同。
null字符串通常用于字符串连接和与其他字符串的比较操作。
C# 空字符串示例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string nullStr = null;
string empStr = string.Empty;
string name = "Onitroad.com";
if ((name != nullStr) || (name != empStr))
{
Console.WriteLine(name + " is neither null nor empty");
}
Console.ReadLine();
}
}
}
日期:2020-04-11 23:03:46 来源:oir作者:oir
