我已经阅读了许多关于此的帖子,但我仍然不确定我是否完全理解这些定义。
以下是我认为不同术语的示例。我是在正确的轨道上,还是我仍然不理解这些概念。谢谢
Array<T TArray> - unbound and open.
Array<int> - bound and closed.
Array<Array<T TArray> - bound and open.
Array<Array<int>> - bound and closed.
未绑定意味着类似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(). 一个类型要么是未绑定的,要么是完全绑定的。如果一个类型是未绑定的,它就没有可以引用类型参数的地方,所以“未绑定和开放”的组合是不可能的。