?? 空合并运算符 --> 合并是什么意思?

发布于 2024-07-16 21:34:28 字数 164 浏览 6 评论 0原文

我很想撒谎说英语是我的第二语言,但事实是我只是不知道“合并”是什么意思。 我知道 ?? 在 C# 中“做什么”,但这个名字对我来说没有意义。

我查了一下这个词,我知道它是“加入”的同义词。 “空连接运算符”仍然没有意义。

有人可以启发我吗?

I'm tempted to lie and say that English is my second language, but the truth is that I just have no idea what 'Coalescing' means. I know what ?? 'does' in C#, but the name doesn't make sense to me.

I looked up the word and I understand it to be a synonym for 'join'. 'Null Join Operator' still doesn't make sense.

Can someone enlighten me?

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

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

发布评论

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

评论(7

£噩梦荏苒 2024-07-23 21:34:28

我很想撒谎说英语是我的第二语言......但事实是我只是不知道“合并”是什么意思。 我知道什么?? 在 C# 中“does”,但这个名称对我来说没有意义。

我查了这个词,我知道它是“加入”的同义词。

我想说对“合并”更准确的描述是“从不同的元素形成一个东西”。 ?? 运算符之所以会发生“合并”,是因为始终从两个值之一解析出单个值。 第一个非空值是结果。

I'm tempted to lie and say that English is my second language...but the truth is that I just have no idea what 'Coalescing' means. I know what ?? 'does' in C#, but the name doesn't make sense to me.

I looked up the word and I understand it to be a synonym for 'join'.

I'd say a more accurate description of "coalesce" would be "to form one thing from different elements". The "coalescing" of the ?? operator happens because a single value is always resolved from one of the two values. The first non-null value is the result.

对不⑦ 2024-07-23 21:34:28

合并是指您有多个项目,但最终只有一个项目 - 通过将这些项目连接在一起或从组中选择单个项目。 对于 ?? 运算符,您将选择该对值中的第一个非空值。

Coalescing is when you have more than one item and then you end up with exactly one—either by joining the items together or by choosing a single item from the group. In the case of the ?? operator, you're choosing the first non-null value of the pair of values.

久伴你 2024-07-23 21:34:28

以下是coalesce的一些其他定义,可能有助于理解。
答案来看,它的意思是“一起成长;融合”或“走到一起,以便形成一个整体。” 换句话说,取出一系列物品并用它们制作一个。 因此,考虑到本讨论中的 null 意味着“空”,将 null 与非空合并即可得到非空。

Here are some other definitions of coalesce that might help make sense.
From Answers, it shows that it means to "grow together; fuse" or "to come together so as to form one whole." In other words, take a sequence of items and make one out of them. So considering that null in this discussion means "empty," coalescing null with a non-empty gives you the non-empty.

冬天旳寂寞 2024-07-23 21:34:28

意思是取第一个非空值。

Meaning take the first non-null value.

撕心裂肺的伤痛 2024-07-23 21:34:28

http://www.merriam-webster.com/dictionary/coalesce

我认为最好的定义是“为了共同的目标而团结起来”。 所以基本上将所有这些结合在一起以获得最好的结果。 用编程术语来说,更多的是获得第一个最好的项目。

http://www.merriam-webster.com/dictionary/coalesce

I think the best definition is the "unite for a common end". So basically pulling it all together to get the best. In programming terms it's more getting the first best item.

深海夜未眠 2024-07-23 21:34:28

这是一个非常古老的问题,但我想添加一个答案。

我认为 C# 语言设计者从 T-SQL 函数中获取了这个词 合并

对问题“SQL中合并的含义” 很好地解释了 SQL 中函数的含义:

SQL 函数实际上是空合并的简写名称。 ID
说这是完全正确的:空合并是
这里突出显示的意思。 区别仅在于两个元素
用于形成结果整体的组合不是这样组合的,而是
比较并选择自:如果第一个元素为 NULL(即纯
虚无),它被忽略; 否则,第二个元素将被忽略。
因此本质上它将 null '合并'(包含)到另一个元素中。
这有点延伸了原来的意思,但绝对是这样
似乎是基于它的开发。

This is a very old question but I wanted to add an answer.

And I think C# language designers took the word from T-SQL function COALESCE.

A comment to the question "The meaning of coalesce in SQL" on English Stack Exchange explains the meaning of function in SQL beautifully in my opinion:

The SQL function is really a shorthand name for null-coalescence. I'd
say this is exactly right: null-coalescence is a subtype of the
highlighted meaning here. The difference is only that the two elements
used to form the resulting whole are not combined as such, but
compared and selected from: if the first element is NULL (i.e., pure
nothingness), it is ignored; otherwise, the second element is ignored.
So essentially it ‘coalesces’ (subsumes) null into the other element.
It is a bit of a stretch of the original meaning, but definitely does
seem to be a development based on it.

城歌 2024-07-23 21:34:28

Coalescing一词源自拉丁语,意思是“将某物连接在一起”。
特别是在物理化学中,它指的是一种现象,其中分散在另一种不混溶液体中的小滴液体倾向于加入较大的液滴,形成更大的聚集体; 这称为“合并”。

在 C# 上下文中,为了扩展,由于 null 合并运算符,这种“连接”发生在变量之间,但结果值取决于第一个操作数是否为 null 的事实,如果是,则结果值将是第二个操作数的值。

Coalescing word derives from Latin language, and means "to join together" something.
In particular it designates in physical chemistry, a phenomenon in which small drops of a liquid dispersed in another immiscible liquid tend to join the larger ones, forming larger aggregates; this is called "Coalescence".

In C# context, for extension, this "join" happens between variables thanks to the null coalescing operator, but the resulting value depends from the fact that the first operand is null or not, if it is, then the reulting value will be that of the second operand.

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