Datatypes in C#
Datatypes in C#
-int ,
-Double, -Structure -Class
-Enumeration -String
-Float -Array
-Object
-Decimal
Value type variables can be assigned a value directly.
The value types directly contain data.
Some examples are int, char, and float, which stores
number, alphabets, and floating point numbers,
respectively.
When you declare an int type, the system allocates
memory to store the value.
The reference type do not contain the actual data
stored in a variable, but they contain a reference to the
variables.
Using multiple variables, the reference types can refer
to a memory location.
If the data memory location is changed by one by one
of the variables, the other variable automatically reflects
this change in value.
Examples are: object, dynamic, and string .
The Object Type is the ultimate base class for all data
type in C# common Type System(CTS).
The object types can be assigned values of any other
types, value types, reference types, predefined or user-
defined types.
When a value type is converted to object type, it is
called boxing and on the other hand.
When an object type is converted to a value type, it is
called unboxing.
Class TestBoxing:{{
Class programe
{
public static void main(string [ ], args );
{
int i =123; //Boxing copies the value of I into object o.
object o = I;
i= 456;
System Console . Write line(“The value-type value={0}”,i);
System Console . Write line(“The object-type value”{0}”,o);
System Console . Read line();
}
}
Output:
The Value-type value = 456
The object-type value = 123
Class Unboxing:
{
public static void main(string[ ],args)
{
string s=“15”; // reference type
int i=“Boxing”; // value type
i=int parse(s); // unboxing
Console.WriteLine(“The value of s=“+s”);
Console.WriteLine(“The value of i=“+i”);
Console.ReadLine();
}
}
OUTPUT: