C# FAQ 1.6 - What are Identifiers and Keywords?
Identifiers are names given to namespaces, classes, methods, variables, and interfaces. An identifier must be a whole word and start with either a letter or an underscore. It can be any combination of letters, numbers, and underscores. But, it should not start with a number. Prior to .NET, programmers were using Hungarian-notation guidelines for naming identifiers; however, with .NET Microsoft has recommended Pascal and Camel notations for identifiers. They have also suggested using semantics in the identifier name. Another point you should bear in mind is that identifiers should not be the same as a C# keyword as listed in the section "Keywords." For example, the following code is illegal:
// Error. int cannot be used as a variable name as it a keyword
int int = 5;
Identifiers in C# are case sensitive. For instance, X is not equal to x. Some programmers use the @ prefix as a first character when declaring identifiers to avoid a clash with a keyword, but it is not a recommended practice. The following names are valid identifiers in C#:
- Hello
- hello
- H_ello
- HelloWorld
- X
- x
Note: In C#, class names can be different from file names.
You should name the variables using the standard DataType prefixes. Also, the first letter after the prefix should be capitalized. Table 1.6.1 shows a list of prefixes for the various .NET DataTypes. You will learn more about DataTypes in Part 3 of C#—Learning with the FAQs.
Table 1.6.1 List of C# Data Types
| Data Type | Prefix | Example |
| Array | arr | arrNumber |
| Boolean | bln | blnSelect |
| Byte | byt | bytNumber |
| Char | chr | chrPick |
| DateTime | dtm | dtmPick |
| Decimal | dec | decPoint |
| Double | dbl | dblData |
| Integer | int | intVar |
| Long | lng | lngMiles |
| Object | obj | objVar |
| Short | shr | shrNumber |
| Single | sng | sngNumber |
| String | str | strAddress |
Interfaces are usually named with an "I" as the first letter. All Windows Forms controls should be named with the special prefixes, as shown in Table 1.6.2. This is to avoid confusion and also to distinguish among other controls in a complex project. As explained above, the first letter after the prefix should be capitalized. Once you master the naming conventions and prefixes, it will be very easy for you to write and debug the code at a later stage.
Table 1.6.2 List of prefixes for Windows Forms controls
| Control Name | Prefix | Example |
| Button | btn | btnSubmit |
| TextBox | txt | txtFname |
| CheckBox | chk | chkHobbies |
| RadioButton | rad | radMale |
| Image | img | imgIndia |
| Label | lbl | lblCity |
| Calendar | cal | calDate |
It is beyond the scope of this FAQ to cover the prefixes of all the .NET controls. You will find a detailed list of them in the MSDN Library. (Perform a search using the phrase "naming guidelines")
Keywords
Keywords are special words built into the C# language and are reserved for specific use. This means you cannot use them for naming your classes, methods, and variables. For instance, if you attempt to use a C# keyword ( if ) as your class name, the C# compiler will emit a runtime error, as shown in Figure 1.6.1.
Figure 1.6.1
To resolve the problem, you may have to change the class name to some other meaningful name. There are around 80 keywords in C#. They are listed in the table given below.
Table 1.6.3 List of C# Keywords
| abstract as |
base bool break byte |
case catch char checked class const continue |
decimal default delegate do double |
| else enum event explicit extern |
false finally fixed float for foreach |
goto | if implicit in int interfaceinternal is |
| lock long |
namespace new null |
object operator outo override |
params private protected public |
| readonly ref return sbyte sealed |
this throw true try typeof |
uint ulong unchecked unsafe ushort using |
short sizeof stackallac static string struct switch |
| virtual void |
For more detailed information about this topic, perform a search on the MSDN Library with the phrase "C# keywords."

Comments
Right Here Is A Technique That Is In fact Aiding adidas-industry experts To Expand
Posted by BobHotgloff on 05/02/2013 09:08amBrief study shows you all details for nike and consequently things one ought to do immediately. [url=http://www.mizunogoruhujp.com/]ããºãã´ã«ã[/url] The Secret For mizuno [url=http://www.mizunogoruhujp.com/ããºã-ã´ã«ãã¯ã©ã-c-1.html]ããºã ã¢ã¤ã¢ã³[/url] Compact report helps you with all the details of the nike together with something you must do right now. [url=http://www.mizunogoruhujp.com/ã´ã«ãã°ãã¼ã-c-33.html]ããºã ã°ãã¼ã[/url] Everything everybody else is doing in regards to mizuno and the thing that youhas to do completely different. [url=http://www.mizunogoruhujp.com/ã´ã«ãããã°-c-7.html]ããºãã´ã«ã[/url] Impartial content material unwraps A number of great new things for nike that none is covering. [url=http://www.mizunogoruhu.com/]ããºã ã¢ã¤ã¢ã³[/url] A meaningful double strain on nike [url=http://www.mizunogoruhu.com/ããºãmizuno-ã¯ã©ã-c-4.html]ããºã mp[/url] Solutions and construction in Vegas - nike has left without any regards [url=http://www.mizunogoruhu.com/ããºãmizuno-ã¢ã¤ã¢ã³-c-3.html]ããºã ã¢ã¤ã¢ã³[/url] Profitable tips on nike that you can use beginning now. [url=http://www.mizunogoruhu.com/ããºãmizuno-ããã°-c-5.html]ããºãã´ã«ã[/url] Brief write-up unwraps the incontestable details of mizuno and the way that it can have an effect on your business.
ReplyC# Valid Identifiers
Posted by Gym.Prathap on 09/20/2012 05:49amC# follows The Unicode Standard, Version 3.0 rules except the Underscore You can use the keyword as identifier provided you have prefix with @ character. But it is not a good programming practice. Wisen Technologies http://wisentechnologies.com/it-courses/.net-training.aspx
ReplyC# tutorials for beginners
Posted by David Allan on 08/11/2012 05:00pmThe intro to keywords and identifiers is pretty good, however its a bit dated now although still relevant and could use some revitalization. You should visit c-sharp station and learningcsharp.co.uk for beginner tutorials, i found them quite helpful when i was learning.
Replyfeedbacl
Posted by pawan on 08/04/2012 12:18amthanks for the such good article,,,
ReplyBad practice
Posted by hzapata on 07/15/2006 12:12pmIs a really bad practice use that prefixes, in OOP you should never need it. If you need prefixes to understand your code, then that code need to be refactorized
ReplyThanks
Posted by koderum on 05/26/2005 06:40pmThank you for the article. That is an explanatory one.
Replyfrom ilango
Posted by ilango on 03/22/2005 10:45amit is very help full fro beginners.
Reply