-1

I have to create a json query dynamically where one of the properties is called "bool". I need 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.

2 Answers2

2

Yes, you put the @ character in front of the variable.

var myquery = new { @bool = "Yes" };
Magnus
  • 45,362
  • 8
  • 80
  • 118
0

You can prefix it with an @.

var myquery = new { @bool = "Yes" };
L01NL
  • 1,753
  • 1
  • 13
  • 17