Type casting is a concept of converting from one data type into another data type.

C# supports two types of type casting

a) Implicit type casting

under control of CLR

Lower to higher

b) Explicit type casting

under control of programmer

higher to lower


Byte to long arrrowimplicit

Int to bytearrrow Explicit

Int to float arrrowimplicit

Float to int arrrowexplicit


C # supports 4 types of Explicit type casting technique

C ++ style of type casting


Boxing and un boxing


Working with C++ style of type casting

Ex :-  int I = 10;

Byte b =  (byte)  I;


DT1   V1 = value;

DT2 V2 =  (DT2) V1;


Example on C++ Style of type casting

Open console application project

Write the following code in main method

Int  I = 150;

Byte Sal =  (byte) I ;

Console . Write Line  (Sal);

Console. Read Line ();

Execute the project (f5)  à 150


In C++ style of typecasting, there is a possibility for loading the data.


Convert is pre- defined class, which is the part of F

Working with convert class is called as “Converting”

Class contains of set of methods.

Predefined methods on convert class

String x = 123

Byte b = convert. To Byte (X);

Convert. To Byte (value)

Convert. To char (value)

Convert. To string (value)

Convert. To Boolean (value)

Convert. To Float (value)





Convert. To INT 16()…………….. for short

Convert. To INT 32()…………….. for int

Convert. To INT 46()…………….. for long

Example on converting

Open Console application project

Write the following code in main method


Class Program


Static void main  (string [] args)


For (int I = 0;I < = 255; I ++)


Char  c = Convert. To char (i);

Console. write (c);


Console . Read line ();





Working with Boxing and Un Boxing





Boxing is a concept of converting value type in to reference types.

Un Boxing is a concept of converting reference type in to  value types.


Console application are especially designed for character based operating system like DOS

As of now, CLR software is not yet introduced for DOS OS, hence console Applications are not Executable in DOS OS.

Console Application contains only LOGIC . but not GUI

In order to develop GUI , Applications Microsoft introduced “Windows forms application” template.