Rob P.
Rob P.

Reputation: 15091

?? Null Coalescing Operator --> What does coalescing mean?

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?

Upvotes: 64

Views: 8759

Answers (7)

tbaskan
tbaskan

Reputation: 520

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.

Upvotes: 2

Ciro Corvino
Ciro Corvino

Reputation: 2128

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.

Upvotes: 0

John Feminella
John Feminella

Reputation: 311665

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.

Upvotes: 45

Robin Day
Robin Day

Reputation: 102538

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.

Upvotes: 2

Erich Mirabal
Erich Mirabal

Reputation: 10048

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.

Upvotes: 9

Mark Cidade
Mark Cidade

Reputation: 100027

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.

Upvotes: 22

p.campbell
p.campbell

Reputation: 100607

Meaning take the first non-null value.

Upvotes: 6

Related Questions