What are Identifiers and Keywords?
Identifiers are the names given to classes, methods, variables and interfaces. It must be a whole word and starts with either an alphabet or an underscore. They are case sensitive. The main point you should bear in mind is that the names should not clash with C# keywords. Some programmers use @ prefix as a first character while declaring identifiers to avoid clash with a keyword but it is not a recommended practice. Following names are valid identifiers in C#
1. Hello
2. hello
3. H_ello
4. HelloWorld
You should name the variables using the standard DataType prefixes. Also the first alphabet after the prefix should be capitalized. Table 1 shows a list of prefixes for the various .NET DataTypes. Interfaces should be named with "I" as the first alphabet so that you can easily distinguish it from a class.
Table 1
|
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 |
All Windows Forms controls should be named with the special prefixes as shown in Table 2. This is to avoid confusion and also to distinguish between other controls in a complex project. As explained above, the first alphabet after the prefix should be capitalized. Once you master the naming conventions and prefixes it would be very easy for you to write and maintain code.
Table 2
|
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 chapter to cover the prefixes of all the .NET controls. You will find a detailed list of them on the MSDN Library. 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 runtime error as shown in Figure 1.
In order to resolve the problem, you may have to change the class name to some other meaningful name. There are around 80 keywords in C#, which can be used by programmers to develop applications using the user friendly language.
Categories: C#, Channels, Latest Tags: .net framework, C#, identifiers, keywords, microsoft
What are Namespaces?
As I explained in a previous FAQ, namespaces are placed at the top of the .NET hierarchy. Namespaces are nothing but group of classes or types or assemblies. Each of these classes contains lot of methods. Basically, namespaces are treated as containers for all classes and are classified into several categories, based on its functionalities. For example, if you need to work with databases, you have to call the namespace System.Data. Similarly, if you are working with files you have to call System.IO namespace.
Namespaces in C# are similar to packages in Java, where we will use a statement like java.sql.* Moreover, all C# programs should call System namespace. This is the root of all other namespaces in the .NET Framework.
Categories: C#, Channels, Latest Tags: .net framework, briefly about c# and c# tools, c sharp compiler download, C#, c# compilers, C# keywords classified, develop in c# in windows98, download C# compiler for windows xp, download different Types Of Compilers in C#, explain briefly about c# and c# tools, multiform application in C#.Net, namespaces
What do you mean by .NET Framework Class Libraries?
The .NET framework class libraries are the core part of any .NET Framework programming language. It contains around 3400 classes classified logically into namespaces. Each class contains numerous methods and properties which you will use for your programming tasks. These libraries are available for any language under the Common Language Runtime environment.
Categories: C#, Channels, Latest Tags: .net framework, briefly about c# and c# tools, c sharp compiler download, C#, c# compilers, C# keywords classified, develop in c# in windows98, download C# compiler for windows xp, download different Types Of Compilers in C#, explain briefly about c# and c# tools, microsoft, multiform application in C#.Net