A good type conversion method has been provided in C#, so when performing type conversion, you can choose as follows.
type conversion |
use selection |
Object => known reference type |
Use the as operator to complete |
Object => known value type |
First use the is operator to judge, and then use type coercion to convert |
Converting between known reference types |
First, you need to provide a conversion function for the corresponding type, and then use type coercion to convert |
Convert between known value types |
It is better to use the static methods involved in the Convert class provided by the system |