Cast to a type from the type name as a string

前端 未结 2 1975
耶瑟儿~
耶瑟儿~ 2020-12-18 23:14

I have an existing base type and I would like to cast it to a derived type base upon the name of the type as a string, so something like this:

public void Do         


        
2条回答
  •  猫巷女王i
    2020-12-18 23:48

    I'll repeat the advice that you probably don't need to do this, but because I have done this operation before:

    Convert.ChangeType(ItemToCast, Type.GetType(stringNameOfType)))

    Should work for you.

提交回复
热议问题