首页 \ 问答 \ 泛型类型的多个地方(Multiple where for generic type)

泛型类型的多个地方(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
更新时间:2024-01-12 06:01

最满意答案

为了解决这个问题,我很想调试循环内部以查看注释的价值,并确保实际调用它。 不应该是: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"

相关问答

更多