Dirk Boer
Dirk Boer

Reputation: 9065

Use a keyword in dynamic context in C#

dynamic json = new JsonObject();
json.ref.lolCats = GetLolCats();

gives me:

Identifier expected; 'ref' is a keyword

is there a way to escape the keyword using the dynamic syntax?

(so no json["ref"].lolCats )

Upvotes: 0

Views: 138

Answers (1)

Carlos Landeras
Carlos Landeras

Reputation: 11063

ref is used for reference parameters. It is a protected keyword. Try using another var name or append @ character before ref.

You can declare variables that use reserved keywords using the @:

private string @int;

Upvotes: 6

Related Questions