Array of a generic class with unspecified type

前端 未结 8 779
长发绾君心
长发绾君心 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:47

    Not directly. A closed generic is a specific "type" behind the scenes, so even an open generic is too general to be a "strong type".

    The best solution I can think of, which I've used before, is to create a non-generic ancestor to the generic class. Whether that solution will function depends on what you plan to use the array for.

提交回复
热议问题