Declare a variable using a Type variable

后端 未结 6 1477
借酒劲吻你
借酒劲吻你 2020-12-06 09:28

I have this code:

Type leftType = workItem[LeftFieldName].GetType();

I then want to declare a variable of that type:

leftTy         


        
6条回答
  •  醉酒成梦
    2020-12-06 09:56

    GetType is evaluated at run-time, and non-dynamic declaration is at compile-time (it does get more specific than that, yes), so no. Even var will require you to assign a value to it that is of unambiguous type.

提交回复
热议问题