問題:
The title is kind of obscure.標題有點晦澀。 What I want to know is if this is possible:我想知道的是這是否可能:
string typeName = <read type name from somwhere>;
Type myType = Type.GetType(typeName);
MyGenericClass<myType> myGenericClass = new MyGenericClass<myType>();
Obviously, MyGenericClass is described as:顯然,MyGenericClass 被描述爲:
public class MyGenericClass<T>
Right now, the compiler complains that 'The type or namespace 'myType' could not be found." There has got to be a way to do this.現在,編譯器抱怨“找不到類型或命名空間‘myType’。”必須有辦法做到這一點。
解決方案:
參考一: https://en.stackoom.com/question/17EB參考二: https://stackoom.com/question/17EB