Keywords are the words which are language specific. A keyword is an essential part of a language definition. These words cannot be used as identifiers. Identifiers are nothing but names given to various entities used in a program. The examples of keywords are event, byte, break, using, class..etc
Identifiers are program-defined tokens. Identifiers are names of various program elements like classes, methods, variables, namespaces, interfaces...etc. in the code that uniquely identify an element. Now let us see what these entities are.
A class contains some common properties and behaviors of an object. A method defines how an object behaves. Variables are placeholders for storing the values used in a program according to the type of data to be stored. Namespace help in organizing the classes so that they can be found easily. When two classes of are of same name, namespaces help in distinguishing these classes. That is different namespaces can be uesd to access these classes. Once a namespace is imported, we don't have to qualify items in that namespace by listing the entire namespace when we refer to them. An interface separates the definition of an objects from their implementation.
There are certain rules for C# identifiers :
- They can have alphabets,digits, and underscore characters
- They must not begin with digits
- Upper case and lower case letters are distinct because C# is a case sensitive language
- Keywords cannot be used as identifiers
The data types in C# are primarily categorized in three parts :
- Value Types
- Reference Types
- Pointer Types
We can further categorize value types in two parts : User-defined types and Pre-defined types.
|Type||Signed||Size in Bytes||Possible Values(Range)|
|sbyte||Yes||1||-128 to 127|
|short||Yes||2||-32768 to 32767|
|int||Yes||4||-2147483648 to 2147483647|
|long||Yes||8||-9223372036854775808 to 9223372036854775807|
|byte||No||1||0 to 255|
|ushort||No||2||0 to 65535|
|uint||No||4||0 to 4294967295|
|ulong||No||8||0 to 18446744073709551615|
|float||Yes||4||Approximately +/- 1.5*10^-45 to +/- 3.4*10^38 with 7 significant figures|
|double||Yes||8||Approximately +/- 5.0*10^-324 to +/- 1.7*10^308 with 15 or 16 significant figures|
|decimal||Yes||12||Approximately +/- 1.0*10^-28 to +/- 7.9*10^28 with 28 or 29 significant figures|
|char||N/A||2||Any Unicode character(16 bit)|
|bool||N/A||1/2||true or false|
- Numeric Types
- Boolean Types
- Character Types
Integral Types : Integral types hold whole numbers for example 123, -123, 3456, etc. The size and sign of the values depend on the integral data type we choose. Integral data type consists of two subtypes: Signed and Unsigned, each of which supports four types of integers. Signed integers support both positive and negative numbers while Unsigned integers holds only positive numbers.
Floating Point Types : In addition to whole number a floating point type can also hold a fractional part of a number such as -123.45 and 123.56. It can be further divided into two parts like float and double. To specify a number to be of float type, you must append the character f to the value such as 12.4f. If you omit f, the value will be treated as double. Here is the syntax for floating point variables:
- float percent = 67.4f;
- double val = 3.4;
- decimal money = 123.45M;
- char c = 'w';
- bool cond = true;
- Classes : As we know that C# is purely an object oriented language so the base of all C# programs is the concept of class; classes provide the best approach to group together logically related items and functions that work on them.
- Interfaces : Interfaces are used as superclasses whose properties are inherited by classes; the concept of an interface came into scene to support multiple inheritance(inheriting from more than one superclass) because in C# a class does not support multiple inheritance; extending the functionalities and behavior of one class into another class into another is called inheritance.
- Delegates : Delegates are objects which point towards a method which matches its signature (values passed to the method) to that delegate; delegates are reference type used to encapsulate a method with a specific signature; in C++, this task could be performed by having pointer to a function.
- Arrays : An Array is an ordered arrangement of data elements; in technical words, it contains a number of variables of the same type with the same name at contiguous locations of memory.
- Object Type : The object type is the ultimate base type of all other pre-defined and user-defined data type in C#; you can use the object type to convert a value type on a disk to an object type to be placed on the heap.
- String Type : String type is for creating and manipulating textual data in C#; you can perform various operations on strings such as copying, comparing, and concatenation on these string objects.
In next article we will see All about Collections in C#.Net
Comments/Suggestions are invited. Happy coding......!
Comments Post a Comment
aijaz 9/30/2011 (IST) / Reply