110,566
社区成员
发帖
与我相关
我的任务
分享
string temp1 = "";
string temp2 = null; //注意赋值Null,和String.Empty的效果应该是一样的
try
{
temp1.Length; //此处正常执行,因为temp1中字符串的长度为0
temp2.Length; //将会引发一个空引用的异常,因为赋Null值本身并没有创建一个字符串的实例
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}