C # variable keywords

The code has the following loop:

foreach (var event in events)
{
...
{

In courses, we cannot name the variable "event" because it is a keyword. Which method is more suitable in such cases: use the @ (@ event) prefix or use another name, for example, "currentEvent"?

+5
source share
7 answers

Definitely use a different name.

Keyword variables are a really cool C # feature, but they should be used for interaction.

+15
source

I usually refuse to use the prefix @. (I sometimes use it to indicate the first parameter in an extension method @this, but even that is pretty rare.)

, - . , ?

+5

@ , . .

, . , . , , , , @ .

+3

, . , , - executableEvent.

, - , , evt. , , .

+1

@ _ , . , :

foreach (var uiEvent in uiEvents)
{
...
{

( )

foreach (var evt in events)
{
...
{

( )

+1

e, _event currentEvent

+1

I would advise you not to use @, so you need to choose a different name. Like some of them, you can enter your name in a more specific type of event

0
source

All Articles