Darrell Norton's Blog [MVP]

Sponsors

The Lounge

News

  • Darrell Norton pic

    MVP logo

    View Darrell Norton's profile on LinkedIn

    Currently Reading:

    weewar.com

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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!


Posted 08-21-2003 8:31 AM by Darrell Norton

[Advertisement]

Comments

Stuart wrote re: Verbatim Identifier
on 08-21-2003 1:17 PM
"Thanks Mike" - I think his name is Mark not Mike. :)
Darrell wrote re: Verbatim Identifier
on 08-21-2003 3:14 PM
Duh, ok updated.
Paul Laudeman wrote re: Verbatim Identifier
on 08-22-2003 1:29 AM

For anyone who is intersted, the way to escape keywords in Visaul Basic .NET is with brackets enclosing the keyword. For example:

Public Property MyVariable as MyEnumType
Get

Return _myVariableType

End Get
Set(ByVal Value As CalculationType)

If (Not [Enum].IsDefined(Value.GetType, Value)) Then
Throw New ArgumentException("Specified type is not valid.")
End If

_myVariableType = Value

End Set
End Property

(notice the brackets around the keyword Enum)
Darrell Norton's Blog wrote [Verbatim Identifiers: Part 2]
on 08-25-2003 4:05 PM