0

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

public string operator;

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

3
  • 4
    @operator should work. I'd recommend not using keywords as identifiers though. Commented Sep 30, 2019 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 Commented Sep 30, 2019 at 22:22
  • Synonyms for operator: driver engineer operative operant Commented Sep 30, 2019 at 22:31

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Use public string @operator.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.