Thursday, April 21, 2016

Explicit Conversion

In this conversion it requires cast operator. The casting is required when the information is lost or the conversion or the conversion is not succeeded. It converts integer values into higher or lower range, converting base class instance to derived class. Let us have a look on example:
using System;
namespace ConsoleApplication1
{
 class Explicit 
 {
 static void Main (string [] args) 
 {
 double d = 10.50; 
 int i;
 
 // casting double to int.
 i = (int) d;
 Console.WriteLine (i);
 Console.ReadKey ();
 }
 }
}
Output : 10

No comments: