Implicitly-Typed conversions:
Small range to large range;
Char to other types is possible, and vice versa.
Display Type conversions:
Simple Type
- char a = (char) 1; Simple type of conversion, compile times wrong. (4.6 to 4, straight to decimal)
- int b = Convert.ToInt32 (123.4); Simple type of conversion, execution times wrong. (4.6 is 5, rounded, decimal is 5 o'clock, return even)
- int c = Int32.Parse ("123"); Only string to number, execution times wrong. ("4.6" simultaneous failed with format error)
2 and 3 differences: The result of Convert.ToInt32 (null) is 0,int32.parse (null) ArgumentNullException exception.
Reference type
| Key words |
Data type |
Parameter relationships |
Run-time failure |
| CType |
Any data type |
Widening or narrowing conversions must be defined between two types of data |
Trigger InvalidCastException |
| DirectCast |
Any data type |
A type must inherit from or implement another type |
Trigger InvalidCastException |
| TryCast |
Reference type only |
A type must inherit from or implement another type |
Return Nothing |
Dim p as Product
p = CType (obj, Product)
p = DirectCast (obj, Product)
Example: c = DirectCast (f, System.Windows.Forms.Control) The best efficiency
P =trycast (obj, Product)
. Net Data Type conversions