Using @ prefix for variable name

1.2k Views Asked by At

In my domain model I have an Event entity. This means that I have to sometimes declare variables as: @event since event is a reserved key word.

I've read on a few stack overflow posts (like What's the use/meaning of the @ character in variable names in C#?) that this is not recommended unless you're interacting with other programming languages. My question is why is it not recommended? What is the issue with using @?

I could use an "Occasion" entity instead but that would mean in my UI layer I would have events which maps to occasions?

1

There are 1 best solutions below

0
On BEST ANSWER

What you're trying to do is the entire purpose of the @ prefix to prevent name clashes.

But this text from MSDN says everything you're asking:

The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style.

Source

So it just comes down to style, in your case it's the right solution if you don't want to rename your entity.