且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

打开,关闭,绑定和未绑定的通用类型

更新时间:2023-10-02 10:03:52

未绑定意味着类似 typeof(Dictionary<,>)之类的东西.未绑定类型仅对反射很有趣,并且只能在 typeof()中使用,而不能在任何其他上下文中使用.所有未绑定类型都是封闭类型,不可能同时使用未绑定和打开"组合.

Unbound means something like typeof(Dictionary<,>). Unbound types are only interesting for Reflection and can only be used in typeof(), not in any other context. All unbounds types are closed types, the combination "unbound and open" is impossible.

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

Assuming T is a type parameter of the current class/method:

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"的组合是不可能的.

Note that there is no such thing as List<Dictionary<,>> - unbound types cannot be used as type arguments, only directly in typeof(). A type is either unbound, or completely bound. And if a type is unbound, there's no place where it could refer to a type parameter, so the combination "unbound and open" is impossible.