Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use a reserved keyword as an identifier in my JSON model class?

I have never used Web API before, but I need a web service that will accept/return JSON objects and using this seemed like a reasonable thing. It looked pretty simple (if not a bit of overkill for my purposes), but a data structure I need to deal with looks something like:

{
    "values":["foo", "bar"],
    "default":"bar"
}

And so I went to make a Model object:

class DropDownValues {
    public string[] values { get; set; }
    public string default { get; set; }
}

Problem is that default seems to be a protected keyword. There must be some way to get around that, right?

like image 682
Michael Holman Avatar asked May 23 '13 02:05

Michael Holman


1 Answers

You can use keywords in C# as identifiers by prepending @ in front of them.

like image 140
muratgu Avatar answered Oct 21 '22 03:10

muratgu