泛型类型的多个地方(Multiple where for generic type)
我需要指定我的类的泛型类型实现了一个接口,并且也是一个引用类型。 我试了下面的代码片段,但都没有工作
public abstract class MyClass<TMyType> where TMyType : IMyInterface where TMyType : class public abstract class MyClass<TMyType> where TMyType : class, IMyInterface
我无法为类型指定多个where子句,是否可以这样做?
I need to specify that a generic type for my class implements an interface, and is also a reference type. I tried both the code snippets below but neither work
public abstract class MyClass<TMyType> where TMyType : IMyInterface where TMyType : class public abstract class MyClass<TMyType> where TMyType : class, IMyInterface
I'm unable to specify multiple where clauses for a type, is it possible to do this?
原文:https://stackoverflow.com/questions/980418
最满意答案
为了解决这个问题,我很想调试循环内部以查看注释的价值,并确保实际调用它。 不应该是:self.comments.each do | comment | ...? 也许你错过了对“每个”的呼唤
To solve this I would be tempted to debug inside the loop to see what the value of comment is and to ensure it is actually being called. Shouldn't ot be: self.comments.each do |comment| ...? Perhaps you are missing a call to "each"
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
ActiveRecord:通过循环集合重新分配子集失败(ActiveRecord: Reassign children by looping a collection fails)[2021-08-30]
为了解决这个问题,我很想调试循环内部以查看注释的价值,并确保实际调用它。 不应该是:self.comments.each do | comment | ...? 也许你错过了对“每个”的呼唤 To solve this I would be tempted to debug inside the loop to see what the value of comment is and to ensure it is actually being called. Shouldn't ot be: self.c ... -
如果要克隆的类与示例中一样简单,则可以使用MemberwiseClone方法创建对象的浅表副本。 为此,您需要在类中实现一个方法,该方法在受保护时访问MemberwiseClone : public class A { public int X; public A Clone() { return (A) MemberwiseClone(); } } 然后改变线 Collection[1] = Collection[0]; 至 Collection[1] ...
-
不能重新分配$这个变量(Cannot reassign $this variable)[2022-05-13]
$this不能被覆盖,它是对你所在对象的引用。如果你可以覆盖它,你会失去这个对象。 在你的代码中你有这条线 public function isUsernameAvailable($this->input->post('username')) 这会导致函数isUsernameAvailable第一个参数是名称$this->input->post('username') 。 这会导致函数范围中的$this被覆盖。 $this can not be overwritten, it is the referen ... -
您可以使用默认的JavaConverters。 import scala.collection.JavaConverters._ val list = new java.util.ArrayList(res.keySet.asJavaCollection) 我没有明白你为什么需要清除,是否需要一次传递ArrayList并稍后更新它的内容? You can use default JavaConverters. import scala.collection.JavaConverters._ ...
-
如果你坚持可变性,你可以这样做: var followingIds = Set("foo", "bar") followingIds = followingIds.map(e => new ObjectId(e)) 但是你可以用不变的东西使你的代码更加糟糕: val followingIds = Set("foo", "bar") val objectIds = followingIds.map(e => new ObjectId(e)) 现在变量(值)名称是相当具有描述性的 If you insist ...
-
首先,我强烈建议以常规方式调用S3方法,而不是通过
-
CSS 3选择器是最好的方式(无论如何更多的是外观问题) 我可以使用 - CSS3选择器 看起来87.18%的全球使用情况对它有利 我还会看看Selectivizr的IE 6-8功能 如果你支持IE <6井,那么骨干断裂。 其他选择: 您的数据真的是一个群组列表吗? 样式可以应用于容器元素吗? 即UL边界权利 你最好不要在一个小组中有一个固定的号码但是要有回应吗? 可以理解的是,对于您的数据而言,这些都是一种新的建议,但取决于它是什么,以及您尝试做什么,实际上可能会有效。 CSS 3 selector is ...
-
VBA通过集合循环(VBA Looping through a Collection)[2022-05-15]
SelectManyFiles返回的集合不返回对象集合。 它可能会返回一系列字符串,但这只是猜测。 将您的子更改为此 Sub Main() Dim Drawing As Variant Dim Drawings As Collection Set Drawings = SelectManyFiles() For Each Drawing In Drawings Debug.Print TypeName(Drawing) Next Drawing End Sub 并查看Debug.Print为您 ...