As you can probably tell from the flood of comments, there isn't really a good, satisfying answer to your question. I will give it a try, though:
1. Why is the '@' symbol allowed by the compiler here when it does not affect its value?
Because that's what the language specification says. The @ symbol before a token does not mean "The next token is a keyword but treat it like an identifer." That's not how the spec is written, so that's not how the language compiler works. Rather, it means "whatever the next token is, treat it like an identifier, even if it happens to be a keyword".
It's the same as saying, for example, "pretend blue were a color". That's easy to do, because blue is a color. Similar, saying "pretend myCollection
is not a C# keyword" is easy -- it's not a C# keyword, so there's nothing to do.
What you're really trying to ask, I suspect, is:
1b. Why did the people who designed C# define the behavior of the @
symbol this way?
That question, I'm afraid, only someone who helped define C# can answer. We can guess, and the answer is almost certainly going to be the one several people already commented on: because that way was easier (to explain, document, implement, test, etc.) and had no downside. Well, apart from some mild confusion on the part of some developers. :)
Adding a requirement in the spec that the compiler do something upon "abuse" of the @
symbol means a lot of work. You have to define what it does (is it a warning? error?), you have to add correct, accurate, proofread, unambiguous language to the spec, you have to add code into the compiler to produce the new behavior, you have to document the new behavior, you have to write test scripts to exercise the new behavior, etc. All for a "feature" that has zero added benefit.
It does make the usage of @ redundant, but C# lets you do lots of redundant things, for various reasons. You can add redundant ()
, you can add redundant delegate constructors, you can add redundant accessibility keywords. And, as you can see, you can add redundant @
's all over the place, if you want.
2. Can the '@' symbol change the values in any scenario as mentioned above?
This one, we can answer: No. If you place @
before a token that's already an identifier, it will be treated as an identifier -- the exact same identifier the the compiler was going to reference anyway. You won't see any change in behavior, it's just extra typing.