Array of a generic class with unspecified type

前端 未结 8 798
长发绾君心
长发绾君心 2021-01-11 18:32

Is it possible in C# to create an array of unspecified generic types? Something along the lines of this:

ShaderParam<>[] params = new ShaderParam<&g         


        
8条回答
  •  庸人自扰
    2021-01-11 18:49

    It's not possible. In the case where the generic type is under your control, you can create a non-generic base type, e.g.

    ShaderParam[] params = new ShaderParam[5]; // Note no generics
    params[0] = new ShaderParam(); // If ShaderParam extends ShaderParam
    

    My guess is that this is an XNA type you have no control over though.

提交回复
热议问题