C#不是可以用 as 来转换类型吗,但不能用于KeyValuePair。我有一句是这样的 System.Collections.Generic.KeyValuePair<string, string> specializedData = data as System.Collections.Generic.KeyValuePair<string, string>;编译器返回出错信息 Error 10 The as operator must be used with a reference type or nullable type ('System.Collections.Generic.KeyValuePair<string,string>' is a non-nullable value type) 我的data本来就是这个数据类型的,我应该怎们转换才可以呢。
as关键字
用于在兼容的引用类型之间执行转换
as 运算符只执行引用转换和装箱转换。as 运算符无法执行其他转换,如用户定义的转换,这类转换应使用强制转换表达式来执行。