泛型 - 开放和封闭的构造类型 [英] Generics -Open and closed constructed Types

查看:165
本文介绍了泛型 - 开放和封闭的构造类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我注意到,构造泛型类型可以是开放的,closed.But我不能做什么他们实际上mean.can你举一个简单的例子吗?

Recently i noticed that Generics constructed types can be open and closed.But I am unable what do they actually mean.can you give a simple example?

推荐答案

在实践中的术语都无所谓了 - 我不记得上一次我不得不担心它的除了的当试图写它。

In practice the terminology doesn't really matter much - I can't remember the last time I had to worry about it except when trying to write about it.


  • 绑定的类型也没有指定类型的参数

  • A 构建的类型至少有一个类型参数指定

  • A型参数是的开放式

  • 的数组类型,其中的元素类型是开放的是一个的开放式

  • 打开的构造类型都有至少一种类型的参数,它是一个开放型

  • A 关闭的类型是任何类型的不开放

  • An unbound type has no type arguments specified
  • A constructed type has at least one type argument specified
  • A type parameter is an open type
  • An array type where the element type is open is an open type
  • An open constructed type has at least one type argument which is an open type
  • A closed type is any type which isn't open

(有嵌套类型的其他规则。请教C#3.0规范4.4节血淋淋的细节。)

(There are further rules for nested types. Consult the C# 3.0 spec section 4.4 for gory details.)

作为一个开放的构造类型的一个例子,考虑:

As an example of an open constructed type, consider:

public class NameDictionary<T> : Dictionary<string, T>

的基类中的typeof(NameDictionary&LT;&GT;)是:


  • 建造,因为它指定类型参数

  • 开启,因为第二个类型参数( T )是一个开放式

  • Constructed because it specifies type arguments
  • Open because the second type argument (T) is an open type

MSDN文档的<一个href=\"http://msdn.microsoft.com/en-us/library/system.type.isgenerictype.aspx\"><$c$c>Type.IsGenericType有相当有用的小桌子。

The MSDN docs for Type.IsGenericType have quite a useful little table.

只是重申一下,这是日常使用几乎完全是不重要的。

Just to reiterate, this is almost entirely unimportant in day to day use.

我一般赞成知道正确的术语 - 尤其是对像按引用传递等等 - 但在这种情况下,它真的,真的不上来非常频繁。我想不用担心它积极鼓励你:)

I'm generally in favour of knowing the correct terminology - particularly for things like "pass by reference" etc - but in this case it really, really doesn't come up very often. I would like to actively discourage you from worrying about it :)

这篇关于泛型 - 开放和封闭的构造类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆