c# Anonymous type. How to use datatype name as member name [duplicate]
I have to create a json query dynamically where one of the properties is called "bool". I n开发者_StackOverflow中文版eed this name because the system I send the requests to, expects this naming.
To create the json I use C# anonymous types like:
var myquery = new { bool = "Yes" };
but I'm not allowed to use bool as member name. Is there a fix for that somehow?
I have searched for a solution, without any success. I hope there is an easy fix.
Yes, you put the @
character in front of the variable.
var myquery = new { @bool = "Yes" };
You can prefix it with an @
.
var myquery = new { @bool = "Yes" };
精彩评论