3 ms·
> A limited ability to avoid collisions with "reserved words" ... would be more of a mis-feature than a feature. While I don't necessarily disagree with you, t
by Zecc 3y ago
> A limited ability to avoid collisions with "reserved words" ... would be more of a mis-feature than a feature.
While I don't necessarily disagree with you, there's something I'd like to mention.
C# allows using @ before a variable name which happens to be the same as a keyword to escape the name.
I don't remember the specifics, but it has saved me once when I wanted to create a class shaped exactly like a JSON object I was loading from an external source and one of the fields was a reserved word. For example, this works fine:
class MyClass
{
public int value;
public string @default;
public string @switch;
}
string json = "{\"value\": 8, \"default\": \"something\", \"switch\": \"on\"}";
MyClass o = JObject.Parse(json).ToObject<MyClass>();
Console.WriteLine("default={0}, switch={1}", o.@default, o.@switch);