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
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.
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.
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.
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.
You can start from this youtube video 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.
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.
string final =str1 ?? str2 ?? str3 ??
Meaning take the first non-null value.