C#相当于ISNULL()函数在SQL Server [英] C# equivalent of the IsNull() function in SQL Server

查看:167
本文介绍了C#相当于ISNULL()函数在SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL Server中,你可以使用 ISNULL()函数来检查,如果值为空,如果是,则返回另一个值。现在我想知道是否有在C#中类似的事情

In SQL Server you can use the IsNull() function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar in C#.

例如,我想要做的是这样的:

For example, I want to do something like:

myNewValue = IsNull(myValue, new MyValue());



而不是:

instead of:

if (myValue == null)
  myValue = new MyValue();
myNewValue = myValue;



感谢。

Thanks.

推荐答案

这就是所谓的空合并( ?? )运算符:

It's called the null coalescing (??) operator:

myNewValue = myValue ?? new MyValue();

这篇关于C#相当于ISNULL()函数在SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆