+ 9

What is the basic difference between type casting and type conversion? Also,which is faster? Implicit one or the explicit one?

10th Dec 2016, 5:44 PM
StillSoul‌‌‌‌‌‌‌‌‌‌‌‌‌‍
StillSoul‌‌‌‌‌‌‌‌‌‌‌‌‌‍ - avatar
3 ответов
+ 4
type casting is explicit type conversion type conversion-changing a value from one data type to another. implicit type conversion-when conversion occurs automatically like ints to floats and chars to ints explicit type conversion-u have to tell compiler to change type explicitly obviously implicit is faster as we have something like in int and we are putting it in larger container like floats hence it would not take much time but opposite process would..think:)
10th Dec 2016, 6:06 PM
manish rawat
manish rawat - avatar
+ 3
Type Casting is different from Type Conversion. 1. When one datatype can be implicitly converted to other datatype it is a Type Casting. e.g. int a = 2; long b = a; or class a { } class b : a { } b objB = new b(); b objA = objB; 2. Type Conversion is used when there is no implicit conversion posible from one type to another type then we have to explicitly convert the type. e.g. class person { string name; } class student : person { string standard; } class teacher : person { string subject; } In the above example we can't store student object in to the teacher value or vice versa. We have to explicitly convert the types and have to write type specific converter. .net framework provide the classes for type conversion for data types defined by the language like "Convert".
4th Jan 2017, 3:22 AM
Anant Anand Gupta
Anant Anand Gupta - avatar
+ 1
Type casting is explicit conversion while on the other hand Type conversion is converting one type of data to another. Explicit conversion is faster.
4th Jan 2017, 4:38 PM
Gaurang Mudgal
Gaurang Mudgal - avatar