471,327 Members | 2,653 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,327 software developers and data experts.

Precedence of ?? (null coalescing) operator

The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.htm>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]

--
<http://www.midnightbeach.com>
Jan 1 '06 #1
11 2445
Jon,

The ECMA Standard for C#
(http://www.ecma-international.org/pu...s/Ecma-334.htm, pag.
149) lists the null coalescing op ?? near the bottom of the precedence
table, above the ternary (conditional) and the assignment operators.

Regards,

Octavio
"Jon Shemitz" <jo*@midnightbeach.com> escribió en el mensaje
news:43***************@midnightbeach.com...
The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.htm>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]

--
<http://www.midnightbeach.com>

Jan 1 '06 #2
> The ECMA Standard for C#
(http://www.ecma-international.org/pu...s/Ecma-334.htm, pag.
149) lists the null coalescing op ?? near the bottom of the precedence
table, above the ternary (conditional) and the assignment operators.


Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)
The new ?? operator doesn't seem to be in the precedence table in
VS.05
<ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_csref/html/214e7b83-1a41-4f7c-9867-64e9c0bab39f.htm>,
and I can't seem to find anything about it online.

What's the precedence of the ?? operator?

[It doesn't seem like it would be "Primary" - up there with x.y, f(x),
a[x], x++, x--, new, typeof, checked, and unchecked - but it doesn't
seem "Unary", either. I hope there's not a new category between Unary
and Arithmetic!]


--
<http://www.midnightbeach.com>
Jan 1 '06 #3
Jon,
Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)


Agreed. But anyway, operator precedence in C# seems to me a lot better
designed than in Pascal, right?

Regards,

Octavio
Jan 2 '06 #4
Octavio Hernandez wrote:
Many thanks. Though knowing that there are now FIFTEEN levels of
precedence feels decidedly yucky. ;-)


Agreed. But anyway, operator precedence in C# seems to me a lot better
designed than in Pascal, right?


Actually, Delphi has only four levels of precedence. That involves
silliness like calling bitwise `and` (C#'s & operator) a "multiplier",
but four is better than fifteen, imho.

Though, I do find that C# precedence rarely gets in the way. It
usually does the right thing, without a lot of parens. I'm a bit
dubious about `(Type)(Expr)` code, where you have to parenthesize the
whole expression because casting has such high precedence, but I don't
find that this is all that common an issue.

--
<http://www.midnightbeach.com>
Jan 2 '06 #5
Jon,
Though, I do find that C# precedence rarely gets in the way. It
usually does the right thing, without a lot of parens.


That's exactly what I was thinking about, I find annoying the need for a lot
of parens in Delphi whenever 'and' and 'or' are involved in an expression...

Best regards from a sure buyer of your book,

Octavio Hernandez
Madrid, Spain


Jan 3 '06 #6
Octavio Hernandez wrote:
Best regards from a sure buyer of your book,


Thanks. It's moving along nicely, after a long pause while my shoulder
ligaments grew back after a bike accident. Doing 2nd draft now -
checking against RTM bits, responding to tech reviewer comments, &c.

--
<http://www.midnightbeach.com>
Jan 3 '06 #7
"Octavio Hernandez" <oc*****************@gmail.com> wrote in message
news:uF**************@TK2MSFTNGP12.phx.gbl...
I find annoying the need for a lot of parens in


I have the exact opposite view. I generally code as if there are only
two levels:
* and / come before + and -
Everything else is determined by the parens.(*)

(*) OK, I don't really follow this literally -- e.g. I won't wrap a
obj.member in parens so that the dot-operator is handled first, but further
down the chart -- where the order gets murky, it often better to add a few
"unnecessary parens" rather then count on both the original programmer & the
maintence programmer agree with the standard on the order.

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Jan 3 '06 #8
James,
it often better to add a few "unnecessary parens"...


I understand your point of view, too. I guess the fact that generally
maintain my own code obviously has some influence on my opinion.

Regards - Octavio
Jan 3 '06 #9
Octavio Hernandez <oc*****************@gmail.com> wrote:
it often better to add a few "unnecessary parens"...


I understand your point of view, too. I guess the fact that generally
maintain my own code obviously has some influence on my opinion.


Out of interest - how often do you need to maintain code you wrote over
a year ago? I usually find that code I wrote but haven't looked at for
over a year is as "foreign" to me as code written by others. Maybe
that's just me though. It does mean I try to make things as readable as
possible though :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 3 '06 #10
"Jon Skeet [C# MVP]" wrote:
Out of interest - how often do you need to maintain code you wrote over
a year ago?
Not very often. Occasionally one of the little applets I throw
together to manage my website fails when it runs into a new edge
condition.
I usually find that code I wrote but haven't looked at for
over a year is as "foreign" to me as code written by others. Maybe
that's just me though. It does mean I try to make things as readable as
possible though :)


I also have that experience. Same response, too.

--
<http://www.midnightbeach.com>
Jan 3 '06 #11
Jon,
I usually find that code I wrote but haven't looked at for
over a year is as "foreign" to me as code written by others.


LOL! Yes, it surely may look a little bit "foreign", but not as "foreign" as
if it was written by someone else I guess :-)

Regards - Octavio


Jan 3 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Sensorflo | last post: by
4 posts views Thread by Master of C++ | last post: by
20 posts views Thread by Vivek N | last post: by
21 posts views Thread by siliconwafer | last post: by
11 posts views Thread by Rupesh | last post: by
9 posts views Thread by Rich | last post: by
5 posts views Thread by junky_fellow | last post: by
9 posts views Thread by marko | last post: by
4 posts views Thread by shapper | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.