简体   繁体   English

C# 动态作为类型参数

[英]C# dynamic as type argument

In the book C# in Depth, section 4.1.4, Jon Skeet calls out two rules for using dynamic:在 C# in Depth 一书中,第 4.1.4 节中,Jon Skeet 提出了两个使用动态的规则:

A type can't specify that it implements an interface using dynamic anywhere in a type argument.类型不能指定它在类型参数的任何位置使用 dynamic 实现接口。

So far so good.到现在为止还挺好。

But right afterwards he states:但紧接着他说:

A class can specify a base class that uses dynamic in a type argument, even as part of an interface type argument.一个类可以指定一个在类型参数中使用 dynamic 的基类,甚至作为接口类型参数的一部分。

So, deriving from a generic class using dynamic as the type argument is fine.因此,使用 dynamic 作为类型参数从泛型类派生很好。 Also good.也很好。 But what does it mean that you can use it "even as part of an interface type argument"?但是,您可以“甚至作为接口类型参数的一部分”使用它是什么意思? What is an "interface type argument"?什么是“接口类型参数”? Isn't that ISomeInterface<TInterfaceTypeArgument> ?那不是ISomeInterface<TInterfaceTypeArgument>吗? Isn't that exactly what's not possible as by the sentence above?这不正是上述句子所不可能做到的吗?

What am I understanding wrong?我理解错了什么?

Ah, I think, I got it:啊,我想,我明白了:

class Derived : Base<ISomeInterface<dynamic>>

is also allowed.也是允许的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM