How to use as and is

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 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326080808&siteId=291194637