string mystr = string.Empty; string mystr = ""; //定义空字符串,两种方法 if (mystr == "" && mystr.Length ==0 && mystr == string.Empty) { CommonClass.MsgBox("yes!"); }
运行弹出提示“yes!”
定为空字符串的几种写法,按照性能从高到低的顺序是:
s.Length == 0 优于 s == string.Empty 优于 s == ""