Define casting of a data type? What are the two types of data type conversions?

 Posted by Tripati_tutu on 12/20/2010 | Category: ASP.NET Interview questions | Views: 2160 | Points: 40

Casting a data type is nothing but converting a variable from one data type to another data type. This can also be called as data type conversion.

There are two types of data type conversions as given below.

Implicit conversions: Here the conversion is type safe i.e. no special syntax is required for this. With this you can convert from derived classes to base classes. In this conversion, there is no chance of data loss.

Explicit conversions: Here the conversion requires a cast operator. Here both source and destination variables are compatible, but might be risk in data loss because of the type or size of destination variable is smaller than the source variable.

class clsBase=new class();

method m=clsBase; //Implicit conversion
class clsDerive=(class) m; //Explicit conversion

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response