Professional Documents
Culture Documents
Contextual Keywords
C# supports a rich and varied slection of data types from built-in types, such as integers or strings, to
userdefined types, such as enumerations, structures and classes.
Some Important Point.
All variable whether user defined pr instrinsic (built-in), can be used as objects anywhere in a
program.
All variables in a program are automatically initialized to default values by the system when they are
declared.
In C# datatype are categorized into three simple organizational structures. Value types
Reference types
Pointer types
Notes:
Pointer types in C# offer the same capabilities as offered by C and C++ language. both, pointers and
references represent memory address but the difference is that references are tracked by the
garbage collector and pointer are not. Also, we can perform arithmetic operations on pointers but
not in references.
Variable and constant deal with the data values and memory locations.
The variable is the memory location whose size depends on the data type.
The memory reserved for the variables of different data type are different.
Constants are the fixed values assigned to a constant variable. These values remain unchanged
throughout the execution of the program.
Value Type:
Value types allow you to store the data directly into the variable. They are derived from
System.ValueType and have a special hehavior in CLR.
The value types and their cantent are stored at the same location in memory.
The default values of value types are stored on stack.
Value type
bool
byte
char
decimal
double
float
int long
sbyte
short
uint
ulong
ushort
Ranges
True or False
0 to 255
U+0000 to U+ffff
-128 to 127
-32,768 to 32,767
0 to 4,294,976,295
0 to
18,446,744,073,709,551,615
0 to 65,535
False
\0
0
0
0
0
0
1.
2.
3.
4.
5.
Integral type
Floating Point type
Decimal type
Bollean type
Nullable type
Enumeration Type:
Reference Types:
Predefined Reference types
1. Dynamic type
2. Object type
3. String type
User-defined Reference Types
1.
2.
3.
4.
Classes
Interfaces
Delegates
Arrays
Pointer Types
Type Conversion:
Implicit Conversion
Explicit Conversion/Type Cating
Variables
Constants
Expression and Operators
Operator Precedence
Using the ?? (Null Coalescing) Operator
Using the :: Scope Resolution Operator
Using the is and as Operator