简体   繁体   中英

Using @ prefix for variable name

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?

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.

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