?? 空合并运算符 --> 合并是什么意思?
我很想撒谎说英语是我的第二语言,但事实是我只是不知道“合并”是什么意思。 我知道 ??
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我想说对“合并”更准确的描述是“从不同的元素形成一个东西”。
??
运算符之所以会发生“合并”,是因为始终从两个值之一解析出单个值。 第一个非空值是结果。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.合并是指您有多个项目,但最终只有一个项目 - 通过将这些项目连接在一起或从组中选择单个项目。 对于 ?? 运算符,您将选择该对值中的第一个非空值。
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.
以下是
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," coalescingnull
with a non-empty gives you the non-empty.意思是取第一个非空值。
Meaning take the first non-null value.
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.
这是一个非常古老的问题,但我想添加一个答案。
我认为 C# 语言设计者从 T-SQL 函数中获取了这个词 合并。
对问题“SQL中合并的含义” 很好地解释了 SQL 中函数的含义:
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:
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.