Verbatim Identifier

Mark Michaelis posts about Using @ to Disambiguate Keywords from Identifiers in C#.  So, if you want to call a class “class”, you could do it like this:

class @class
{
    static void
Main()
    {
        @static(false);
    }

    public static void @static(bool @bool)
    {
        if (@bool)
            System. Console.WriteLine("true");
       
else
         
System. Console.WriteLine("false");
    }
}

Or, call a return variable “return”:

public string GetName()
{
    string @return;
    Console.Write("Enter your name:");
   
do
   
{
        @return = Console.ReadLine();
    }
    while (@return.Length == 0);
    return @return;
}

Cool, though it looks like a T-SQL variable now.  Thanks Mark!

Source: Darrell Norton

 

3 Comments

Comments have been disabled for this content.