时间:2021-05-13 08:12:31 | 栏目:.NET代码 | 点击:次
如果一个对象不为空null时,把它赋给另外一个对象:
像下面这个样子,需要把str的值赋给result,前提条件是在不为空null的前提之下:

class Aj
{
public void DemoNUll()
{
string str = null;
string result = "";
}
}
方法一:

if (str == null)
result = "";
else
result = str;
方法二:

if (str != null)
{
result = str;
}
方法三:

result = str == null ? "" : str;
方法四:

result = str ?? "";