Oracle PL/SQL COALESCE 函数的 C# 等效项是什么?

发布于 2024-07-04 21:34:46 字数 243 浏览 8 评论 0原文

是否有一个语句或一行的方法来完成这样的事情,其中​​声明字符串 s 并分配表达式中的第一个非空值?

//pseudo-codeish
string s = Coalesce(string1, string2, string3);

或者,更一般地说,

object obj = Coalesce(obj1, obj2, obj3, ...objx);

Is there a one statement or one line way to accomplish something like this, where the string s is declared AND assigned the first non-null value in the expression?

//pseudo-codeish
string s = Coalesce(string1, string2, string3);

or, more generally,

object obj = Coalesce(obj1, obj2, obj3, ...objx);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花坊 2024-07-11 21:34:46

正如达伦·科普所说。

你的陈述

object obj = Coalesce(obj1, obj2, obj3, ...objx);

可以这样写:

object obj = obj1 ?? obj2 ?? obj3 ?? ... objx;

换句话说:

var a = b ?? c;

相当于

var a = b != null ? b : c;

As Darren Kopp said.

Your statement

object obj = Coalesce(obj1, obj2, obj3, ...objx);

Can be written like this:

object obj = obj1 ?? obj2 ?? obj3 ?? ... objx;

to put it in other words:

var a = b ?? c;

is equivalent to

var a = b != null ? b : c;
强辩 2024-07-11 21:34:46

?? 运算符。

string a = nullstring ?? "empty!";

the ?? operator.

string a = nullstring ?? "empty!";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文