Posts Tagged ‘.net framework’

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.

What are Identifiers and Keywords?

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.

Be the first to comment - What do you think?  Posted by Anand Narayanaswamy - May 23, 2009 at 1:41 am

Categories: C#, Channels, Latest   Tags: , , , ,

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.

Be the first to comment - What do you think?  Posted by Anand Narayanaswamy - May 15, 2009 at 1:14 am

Categories: C#, Channels, Latest   Tags: , ,

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.

Be the first to comment - What do you think?  Posted by Anand Narayanaswamy - May 14, 2009 at 12:57 am

Categories: C#, Channels, Latest   Tags: , ,