我想知道匹配Object Convert.ChangeType( Object object, Type type)类型时内部会发生什么.它只是简短而且回归?objecttypeobject
例如:
object objString = "Hello World";
string converted = (string) Convert.ChangeType( objString, typeof ( String ) );
Run Code Online (Sandbox Code Playgroud)
请问实现ChangeType实际调用IConvertible接口还是只返回objString?
根据Microsoft的C#参考源,Convert.ChangeType(Object, Type)执行以下一般行为:
IConvertible
ToWhatever在输入上调用相应的方法.
return this类型匹配或return Convert.ToWhatever(this)否则,这是排序的快捷方式.ToType输入,传递类型.