-1

How can I declare a variable with name "operator"?

public string operator;

I see the below error, click here to see the picture

GSerg
  • 76,472
  • 17
  • 159
  • 346
SaiV
  • 43
  • 1
  • 9
  • 4
    `@operator` should work. I'd recommend not using keywords as identifiers though. – E. Moffat Sep 30 '19 at 22:16
  • nb : could you please copy-paste (and format) the interesting part of the error message as text into your question ? This is much better for searchability and [many other reasons](https://meta.stackoverflow.com/a/285557/479251) – Pac0 Sep 30 '19 at 22:22
  • Synonyms for operator: driver engineer operative operant – Idemax Sep 30 '19 at 22:31

2 Answers2

3

you can use any reserved word by prefixing the name of your identifier with an @ : @operator

var @operator = "+";
var @event = new { name = "Burning man" };
var @var = 23;
var @enum = new List { 1, 2, 3 };

needless to say, this is not so much helping readability, but if you feel it fits your case, you can use it.

Pac0
  • 21,465
  • 8
  • 65
  • 74
2

Use public string @operator.

The @ prefix allows you to use reserved words as variable names.

Marcell Toth
  • 3,433
  • 1
  • 21
  • 36