Unit I Literals Datatypes in C#
Unit I Literals Datatypes in C#
• Value type stores the value itself, whereas the reference type stores
the address of the value where it is stored.
• Some predefined data types such as
int, float, double, decimal, bool, char, etc. are value types and
object, string, and array are reference types.
• While working with these data types, you often need to convert
value types to reference types or vice-versa.
• Because, both have different characteristics and .NET stores them
differently in the memory, it must do some work internally to
convert them from one type to another.
• These conversion processes are called boxing and UnBoxing.
Value Type
Reference Type
To Print Maximum and Minimum Values of Data types
static void Main(string[] args)
{
Console.WriteLine("Integer Maximum value is " + int.MaxValue);
Console.WriteLine();
Console.WriteLine("Integer Minimumvalue is " + int.MinValue);
Console.WriteLine();
Console.WriteLine("Float Maximum value is " + float.MaxValue);
Console.WriteLine();
Console.WriteLine("Float Minimum value is " + float.MinValue);
Console.WriteLine();
Console.WriteLine("Double Maximum value is " + double.MaxValue);
Console.WriteLine();
Console.WriteLine("Double Minimum value is " + double.MinValue);
Console.WriteLine();
Console.ReadLine();
}
}
}
What is boxing?
1. Boxing is the process of converting a value type to the
object type or any interface type implemented by this
value type.
2. Boxing is implicit.
Implicit:
In C#, Create local variable without specifying its
type.
The C# var keyword is used to create implicit typed
local variables.
The C# compiler infers the types of variable on the basis
of assigned value.
int i = 10;
object o = i; //performs boxing