M_Cyjb_GenericConvert_ChangeType - CYJB/Cyjb GitHub Wiki

GenericConvert.ChangeType 方法 (Object, Type)

返回指定类型的对象,其值等效于指定对象。

Namespace: Cyjb
Assembly: Cyjb (in Cyjb.dll) Version: 1.0.23+7750dd8e971297c5fa962a3bee37fb78f72793f6

语法

C#

public static Object? ChangeType(
	Object? value,
	Type outputType
)

参数

 

value
Type: System.Object
要转换的对象。
outputType
Type: System.Type
要将 value 转换到的类型。

返回值

Type: Object
一个对象,其类型为 outputType, 并且其值等效于 value

Exceptions

 

异常 条件
ArgumentNullException outputTypenull
InvalidCastException valuenull, 而且 outputType 是值类型。
InvalidCastException 不支持此转换。

Remarks

尽可能使用泛型方法 ChangeType(TInput, TOutput)(TInput),这样可以避免额外的类型转换。

参见

Reference

GenericConvert 类
ChangeType 重载
Cyjb 命名空间

⚠️ **GitHub.com Fallback** ⚠️