简体   繁体   中英

C# and VB.NET operator precedence

Looking at the C# and VB.NET language specs I think it says that the logical Xor/Or/And operations have different precendence in the two languages. Am I reading that right? I was expecting them to have the same precendence.

For example in C#

100 | 200 ^ 300 & 400

is the same as...

100 | (200 ^ (300 & 400))

But the equivalent VB.NET

100 Or 200 Xor 300 And 400

as far as I can tell is the same as...

(100 Or 200) Xor (300 And 400)

Am I reading that right?

Personally, I'm not a fan of remembering precedence rules. If there is any ambiguity, I just add brackets. Even if I get it right, somebody else might have to read it, and I don't know which background they'll have...

But I think you are reading it correctly.

Am I reading that right?

Yes. Simple as that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM