Cannot implicitly convert 'string' to 'System.TypeCode'

前端 未结 2 1655
野性不改
野性不改 2021-01-29 00:31

Just wondering if anyone knows how to fix this error? I\'ve also used TypeCode. but still no luck. Thanks

case typeof(Nullable).ToString         


        
2条回答
  •  耶瑟儿~
    2021-01-29 01:00

    Ultimately, typeof(Nullable) isn't a TypeCode, and the string representation of that isn't a TypeCode. There is no TypeCode that represents Nullable specifically.

    You can use Nullable.GetUnderlyingType(type) to check that something is Nullable and get the T at the same time (it returns null if not), and you can use Type.GetTypeCode on the result of that, but: I suspect that in your case, using TypeCode at all may be an error, and simply checking the type itself (if (type == typeof(int?)) {...}) may be better.

提交回复
热议问题