本文介绍了包含不明类型的泛型类的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 是否有可能在C#创建未指定的泛型类型的数组?沿此线的东西: ShaderParam<> [] PARAMS =新ShaderParam<> [5]; PARAMS [0] =新ShaderParam<浮动>(); 或者,这是根本不可能的,因为C#的强类型? 解决方案 这是不可能的。在泛型类型是你的控制之下的情况下,你可以创建一个非泛型的基本类型,如: ShaderParam [] PARAMS =新ShaderParam [5]; //注意没有仿制药 PARAMS [0] =新ShaderParam<浮动>(); //如果ShaderParam< T>扩展ShaderParam 我的猜测是,这是你有过,虽然无法控制的XNA类型。 Is it possible in C# to create an array of unspecified generic types? Something along the lines of this:ShaderParam<>[] params = new ShaderParam<>[5];params[0] = new ShaderParam<float>();Or is this simply not possible due to C#'s strong typing? 解决方案 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 genericsparams[0] = new ShaderParam<float>(); // If ShaderParam<T> extends ShaderParamMy guess is that this is an XNA type you have no control over though. 这篇关于包含不明类型的泛型类的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 07:51