Click here to Skip to main content
12,747,366 members (35,308 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 21 Jun 2011

How to use reserved words as member names.

, 25 Jun 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
This tip shows one way to use reserved words as member names using verbatim identifiers.

Disclaimer: I do not condone the use of this tip. I just find it interesting.

Today, I was using ReSharper to rename some constants in a class. The constants were named inch, pica, and point. I wanted to rename them to in, pc, and pt. Resharper caught the obvious error in my thinking which is that the name in is a reserved keyword in C# (duh).

What I found interesting is that ReSharper didn't go ahead and follow my instructions (thanks!) or tell me I was being dumb for trying to name something using the same name as the reserved word; it renamed it to @in.

Huh. A quick search revealed that yes indeed, any member can begin with the @ character. You learn something new every day. Therefore this code is valid:

public class @foo
    private string @baa = "sheep";

    private void @black()
        Console.Write("Hello" + @sheep);

I also noted that even Intellisense doesn't correctly colour-code when @ is used to prefix a class' name.

Follow-up: Apparently they are called verbatim identifiers. Thanks SubsonicDesignOfficial.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Yvan Rodrigues
Systems Engineer Clearpath Robotics
Canada Canada
Yvan Rodrigues has 25 years of experience in information systems and software development for the industry. He is Senior Systems Developer at Clearpath Robotics

He is a Certified Technician (C.Tech.), a professional designation granted by the Institute of Engineering Technology of Ontario (IETO).

Yvan draws on experience as owner of Red Cell Innovation Inc., Mabel's Labels Inc. as Manager of Systems and Development, and the University of Waterloo as Information Systems Manager.

Yvan supports open-source software. He is a committer for SharpKit (C# to Javascript cross-compiler) and WebIssues (Issue/Ticket Management System), TinyMCE (JavaScript editor), and contributes to MySQL, Ghostscript, iTextSharp, Bacula, FreeBSD, and Xamarin.

You may also be interested in...


Comments and Discussions

GeneralReason for my vote of 3 OK, yes, you can do it. But why is R... Pin
Br.Bill29-Jun-11 8:17
memberBr.Bill29-Jun-11 8:17 
GeneralNice, I learned something. Pin
Walt Fair, Jr.25-Jun-11 16:43
subeditorWalt Fair, Jr.25-Jun-11 16:43 
GeneralReason for my vote of 5 very good trick. Indeed a trick! 5! Pin
JP_Rocks23-Jun-11 2:18
memberJP_Rocks23-Jun-11 2:18 
QuestionInteresting Pin
SubsonicDesignOfficial21-Jun-11 9:48
memberSubsonicDesignOfficial21-Jun-11 9:48 
AnswerRe: Interesting Pin
Yvan Rodrigues21-Jun-11 10:09
memberYvan Rodrigues21-Jun-11 10:09 
GeneralRe: Interesting Pin
SubsonicDesignOfficial21-Jun-11 10:10
memberSubsonicDesignOfficial21-Jun-11 10:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170215.1 | Last Updated 25 Jun 2011
Article Copyright 2011 by Yvan Rodrigues
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid