While coding in C#, I by mistake added a strudel sign before a variable in if statement (instead of exclamation mark).
bool b = false;
if (@b)
{
}
I surprised it compiled successfully without any error.
I wonder: What is the meaning of the above code?
@
can be used to "escape" identifiers, in case you want to use keywords. For example:
int @class = 10;
Of course it's usually a bad idea to use keywords as identifiers, but if you're using a class library which happens to use them, it can be hard to avoid. It can also be useful sometimes to use "@this" for situations where you want to effectively have a this
reference, but for whatever reason you can't use one. (These are pretty few and far between, but I've seen it a couple of times, and it's worth at least knowing about.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With