Notes about type conversion
() Forced conversion Operator
Features:
1. If the type conversion fails, an invalidcastexception will be thrown.
2. As long as the type conversion is true, null does not throw an exception.
Convert type conversion
Features:
1. null values will not throw an exception. For example, convert. tostring (null) will return string. Empty
2. formatexception may be thrown due to incorrect format
As type conversion Operator
Features:
1. Never throw an exception
2. If the input value is null or the conversion fails, null is returned.
Other memos:
The typeof () operator returns the type of a class.
The is operator can determine whether the conversion is successful before forced conversion.
Tostring () function. Because tostring is defined in the object, it can be called for any type, which is convenient. But a little annoying,
The instance of the class cannot be null. Otherwise, an exception is thrown.
Dbnull value, which will be read from the database. This value can be safely called tostring () or convert. tostring, and will return string. Empty
It should be noted that when other functions of the convert class are used, an exception will be thrown when this value is encountered, for example: Convert. todouble (convert. dbnull)