Declare a variable using a Type variable

后端 未结 6 1473
借酒劲吻你
借酒劲吻你 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:59

    No, that is not possible. The type of a variable has to be known at compile time.

    You can declare a variable of type object, it will be capable of storing any data type.

提交回复
热议问题