Simple Types (Primitive Data types)
Simple or value type variables are those, which are assigned space in the stack instead ofthe heap. All the primitive types such as int, double etc are value type variables. The
simple types basically consist of Boolean and Numeric types, where Numeric is further
divided into Integral and Floating Point.
The first rule of value types is that they cannot be null. Anytime you declare a variable of
value type, you have allocated the number of bytes associated with that type on the stack
and are working directly with that allocated array of bits. In addition, when you pass a
variable of value type, you are passing that variable’s value and not a reference to the
underlying object.
Object Type
Object type or reference type variables are those, which are allocated storage space in theheap. Reference type objects can be null. When a reference type is allocated under the
covers a value is allocated on the heap and a reference to that value is returned. There are
basically four reference types: classes, interfaces, delegates and arrays.
Class Type
Custom data types are available in .NET framework in the form of classes or class type. Itis nothing but a set of data and related behavior that is defined by the developer.
Object type and class type are both reference type variables. The only difference comes
from the fact that object type consists of objects predefined and available with the .NET
framework such as string whereas class type consists of custom user defined data types
such as the class employee given below.
Example:-
class employee
{
int empid;
string empname;
public employee()
{
empid = 10;
empname = “Reshmi”;
}
}
Advertisement
0 comments:
Post a Comment