How to convert a TypeCode to an actual type?

后端 未结 5 1721
一向
一向 2021-02-19 03:14

In the code below I get colType which is a code number for the type. But how would I convert that number into the actual type? Thx!!

for (int j = 0;         


        
5条回答
  •  无人共我
    2021-02-19 03:42

    It's even simpler:

    Type type = Type.GetType("System." + colType);
    

    If you want to convert a value to that type you can use the typecode directly

    Convert.ChangeType(value, colType);
    

提交回复
热议问题