Type Safety, Implicit Conversion, and Explicit Conversion
Type Safety and Conversion- by Sagar Jaybhay
Type Safety: – Type safety means preventing type errors. What does it mean?
Implicit Conversion: – When you move one data type to another data type without any data loss then it’s called Implicit Conversion.
For Ex. Int i=10; double b=i;
it is possible because no data loss happened. It’s called Implicit Conversion.
Explicit Conversion: – When you cast bigger data type to small data type and there might be chances of data loss, so you need to specify from which data type to which data type you need to convert explicitly that’s why its called explicit casting. And for implicit casting, there is no need to specify a data type for casting so it’s called implicit casting. For explicit casting .net alerts a developer there may be a chance of data loss.
Conversion: – When you convert from one data type to another data type using convert class it’s conversion.
. String val=”4”; int i=Convert.ToInt32(val);