c# - 我们可以将类型限制为委托(delegate)吗

标签 c# .net

<分区>

我们可以将类型限制为类或结构。我们可以将类型限制为委托(delegate)吗?

最佳答案

Delegate 是一个类,您通常可以指定一个非密封类作为约束。但是,语言规范明确将 System.Delegate 作为第 10.1.5 节中的有效约束排除在外。

A class-type constraint must satisfy the following rules:

  • The type must be a class type.
  • The type must not be sealed.
  • The type must not be one of the following types: System.Array, System.Delegate, System.Enum, or System.ValueType.
  • The type must not be object. Because all types derive from object, such a constraint would have no effect if it were permitted.
  • At most one constraint for a given type parameter can be a class type.

关于c# - 我们可以将类型限制为委托(delegate)吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4161104/

相关文章:

c# - 在 C# 中减去百分比

c# - 如果调试文件夹的其余部分可用,但我的 EXE 运行良好,但不是独立的

c# - .NET Framework 中是否有字母枚举类型?

C# 版本兼容性

.net - 是否有任何模式或实践可以在 .NET 中以非侵入式方式将调试/日志代码引入现有算法?

.net - 如何在 WCF 调用的服务端获取用户名和密码?

c# - 如何从搜索引擎获取使用的关键字

c# - 如何在 Entity Framework 4.1 的 Code-First Fluent API 中以编程方式定义关系

c# - IRequiresSessionState 不起作用

c# - MemoryCache OutOfMemoryException