Array of a generic class with unspecified type

前端 未结 8 730
长发绾君心
长发绾君心 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 19:01

    That wouldn't make sense.

    What would happen if you write params[3]?
    What type would it be?

    You may want to create a non-generic base class or interface and use an array of them.

    0 讨论(0)
  • 2021-01-11 19:09

    No, the concept ShaderParam<> is meaningless as far as an instantiated type is concerned. In other words, a concrete ShaderParam<float> is not an instance of ShaderParam<>. Therefore, the declared type of the array would be illegal for holding that instance. (Above and beyond the fact that it's already illegal syntax to begin with.)

    0 讨论(0)
提交回复
热议问题