??空融合算子 - >合并是什么意思?

时间:2022-01-22 11:46:58

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.

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

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

我查了一下这个词,我理解它是'join'的同义词。 'Null Join Operator'仍然没有意义。

Can someone enlighten me?

有人可以开导我吗?

6 个解决方案

#1


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.

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

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

我查了一下这个词,我理解它是'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.

我会说“合并”的更准确的描述是“从不同的元素形成一件事”。 “合并”的??运算符是因为始终从两个值之一解析单个值。第一个非空值是结果。

#2


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.

合并是指当您有多个项目然后最终只有一个 - 通过将项目连接在一起或从组中选择一个项目。在??的情况下?运算符,您将选择该对值的第一个非空值。

#3


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.

以下是合并的一些其他定义,可能有帮助。从答案中,它表明它意味着“共同成长;融合”或“聚集在一起,形成一个整体”。换句话说,取一系列项目并从中制作一个。因此,考虑到此讨论中的null意味着“空”,使用非空合并null会使非空。

#4


Meaning take the first non-null value.

含义取第一个非空值。

#5


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.

我认为最好的定义是“团结一致”。所以基本上将它们全部拉到一起以获得最佳效果。在编程术语中,它更能获得第一个最好的项目。

#6


You can start from this youtube video http://www.youtube.com/watch?v=YJGGmTNHPeo

您可以从此YouTube视频开始http://www.youtube.com/watch?v=YJGGmTNHPeo

If you see the English meaning of coalescing it says “consolidate together”. Coalescing operator returns the first NON-NULL value from a chain.

如果你看到合并的英文含义,就说“合并在一起”。 Coalescing运算符返回链中的第一个NON-NULL值。

For example below is a simple coalescing code which chains four strings.So if “str1” is null it will try “str2” , if “str2” is null it will try “str3” and so on until it finds a string with a non-null value.

例如下面是一个简单的合并代码,它链接四个字符串。所以如果“str1”为null,它将尝试“str2”,如果“str2”为null,它将尝试“str3”,依此类推,直到找到一个非字符串为止 - 空值。

string final =str1 ??  str2 ?? str3 ??

#1


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.

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

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

我查了一下这个词,我理解它是'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.

我会说“合并”的更准确的描述是“从不同的元素形成一件事”。 “合并”的??运算符是因为始终从两个值之一解析单个值。第一个非空值是结果。

#2


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.

合并是指当您有多个项目然后最终只有一个 - 通过将项目连接在一起或从组中选择一个项目。在??的情况下?运算符,您将选择该对值的第一个非空值。

#3


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.

以下是合并的一些其他定义,可能有帮助。从答案中,它表明它意味着“共同成长;融合”或“聚集在一起,形成一个整体”。换句话说,取一系列项目并从中制作一个。因此,考虑到此讨论中的null意味着“空”,使用非空合并null会使非空。

#4


Meaning take the first non-null value.

含义取第一个非空值。

#5


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.

我认为最好的定义是“团结一致”。所以基本上将它们全部拉到一起以获得最佳效果。在编程术语中,它更能获得第一个最好的项目。

#6


You can start from this youtube video http://www.youtube.com/watch?v=YJGGmTNHPeo

您可以从此YouTube视频开始http://www.youtube.com/watch?v=YJGGmTNHPeo

If you see the English meaning of coalescing it says “consolidate together”. Coalescing operator returns the first NON-NULL value from a chain.

如果你看到合并的英文含义,就说“合并在一起”。 Coalescing运算符返回链中的第一个NON-NULL值。

For example below is a simple coalescing code which chains four strings.So if “str1” is null it will try “str2” , if “str2” is null it will try “str3” and so on until it finds a string with a non-null value.

例如下面是一个简单的合并代码,它链接四个字符串。所以如果“str1”为null,它将尝试“str2”,如果“str2”为null,它将尝试“str3”,依此类推,直到找到一个非字符串为止 - 空值。

string final =str1 ??  str2 ?? str3 ??