c# 杂记

来源:互联网 发布:陕西知含监理公司 编辑:程序博客网 时间:2024/06/05 16:33
1.string.Empty与null      当你只定义一个str而不为其分配内存时用string str=null,但是在接下来你使用它之前必须为它赋值如str=“xxxx”也就是为它初始化。而string str= string.Empty是定义和初始化放在了一起它实际是等价于string str=null;str="";具体使用时,如果你确定在使用前会给str赋值就用string str=null,否则用string str= string.Empty,不然程序运行时可能会引发空指针异常。