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.
Yvan Rodrigues has 30 years of experience in information systems and software development for the industry. He is Senior Concept Designer at
Robotic Assistance Devices
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, the
University of Waterloo as Information Systems Manager, and
OTTO Motors as Senior Systems Engineer and Senior Concept Designer.
Yvan is currently focused on design of embedded systems.