Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make "params" a legal variable name [duplicate]

Tags:

json

c#

asp.net

I have a JSON data to post to http, this JSON data has a var named params:

{
 "method": "...",
 "params": [ ... ],
 "session": "...",
 "id": 1
}

I want to link every request and response to a class in my Models. How can I either use the name params for the attribute or make the attribute name change as I serialize my class to JSON format? I am using ASP.NET MVC 4 and JSON.NET framework on visual studio 2013 Ultimate edition.

like image 524
Yacine Ben Slimene Avatar asked Dec 19 '22 19:12

Yacine Ben Slimene


1 Answers

A property named params (or any other keyword) can be used in C# classes as long as you escape the name using the @ prefix:

class MyClass
{
    public string method { get; set; }
    public Whatever @params { get; set; }
}
like image 196
Heinzi Avatar answered Jan 07 '23 21:01

Heinzi