How to use Keywords in .NET (C#)
If you can use tens and thousands of words as identifier, why should one use the few keywords reserved by C#?
private static void KeywordExample()
{
string string = "Some String";
}
Might be you still want to use ‘bool’, ‘string’ etc. But using this will throw “identifier expected, 'keyword' is a keyword - Compiler Error CS1041”
A reserved word for the C# language was found where an identifier was expected. Replace the keyword with a user-specified identifier.
To overcome this error, prefix the identifier with “@”. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.
private static void KeywordExample()
{
string @string = "Some String";
Console.Write(@string);
}
I would fire IMMEDIATELY anyone who abused their fellow developers by doing that. Horrid, HORRID idea.
ReplyDeleteEasy, IDisposable! What about this use case?
ReplyDeletealthough normally unusual, this solution is great for parsing xml with elements or attributes using reserved words. In example: you have a restriction defined in a xsd file saying "true" and "false". Now, how would you generate a class to serialize/deserialize that without having the @ option?
ReplyDeletewww.hjgode.de/wp
I would fire you! There are legitimate reasons, one of which would be using keywords in an enum and testing against the enum for membership with text.
ReplyDelete