Home > Net >  Why does the code get compiled when I use !!= C#
Why does the code get compiled when I use !!= C#

Time:06-28

I am trying to understand how does the code get compiled when I use (!!=) Apparently the 2 snippets below do the same thing. Why are both permissable?

if (4 !!= 5)
  Console.WriteLine("vvvvvv");

the above does the same thing as:

if (4 != 5)
   Console.WriteLine("vvvvvv");

CodePudding user response:

The expression 4 !!= 5 is parsed as the enter image description here

enter image description here

With sharplab.io kindly highlighting the part of the code which is represented by selected syntax node. So as others described you can see that compiler parses your code as 4 followed by null-forgiving operator.

  •  Tags:  
  • c#
  • Related