2012-02-03 71 views
3

我已阅读了许多关于此的帖子,但我仍然不确定是否完全理解了定义。打开,关闭,绑定和未绑定泛型类型

以下是我认为是不同术语的例子。我在这里的正确轨道,还是我还不理解的概念。谢谢

Array<T TArray> - unbound and open. 
Array<int> - bound and closed. 
Array<Array<T TArray> - bound and open. 
Array<Array<int>> - bound and closed. 

回答

3

没有约束意味着像typeof(Dictionary<,>)。未绑定类型仅适用于Reflection,只能在typeof()中使用,而不能在其他任何上下文中使用。 所有无约束类型都是封闭类型,“无约束和开放”组合是不可能的。

假设T是当前类/方法的类型参数:

Dictionary<,> - unbound and closed 
Dictionary<string, int> - constructed and closed 
Dictionary<int, T> - constructed and open 
Dictionary<string, List<T>> - constructed and open 
NonGenericClass - bound and closed 

注意,有作为List<Dictionary<,>>没有这样的事情 - 未结合的类型不能在typeof()被用作类型参数,仅直接。一种类型或者是未绑定的,或者是完全绑定的。 如果一个类型是未绑定的,那么就没有可以引用类型参数的地方,所以“unbound and open”组合是不可能的。

+0

谢谢丹尼尔。很有帮助。 – 2012-02-09 16:54:41