§ June 28, 2005

All about the @t sign (C# Verbatim Identifier)

Bad form. Bad style. People will hate you. But, its totally legal.

I think I read this back in the language specification somewhere (or maybe a college professor said it), but I had forgotten about it until I read it on someone elses blog.
namespace Test {
    using System;
    public class Test { 
        static void Foo(string @namespace) {
            bool @true = @namespace == "hello";
            if(@true) Console.WriteLine(@namespace);
        }
    }
    
    [STAThread]
    static void Main(string[] args) {
        Test.Foo("hello"); // prints out "hello"
        Test.Foo("world"); // prints nothing
    }
}

Odd eh?

If you're ever have a sudden urge to use a reserved word, and just *HAVE* to have the word "true" as a variable name, @true will work.

Now... if you ever use that in public, you may be bludgeoned to death by co-workers.

its called a "verbatim" identifier, and should only be used in tandem with a goto statement for maximum annoyance.


Posted 13 years, 2 months ago on June 28, 2005

 Comments can be posted in the forums.

© 2003 - 2017 NullFX
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License