因此,在上一个问题中,我询问了有关使用公共类和宾果游戏实现通用接口的问题,它可以工作。但是,我希望传入的类型之一是内置的可为空类型之一,例如:int、Guid、String 等。
这是我的界面:
public interface IOurTemplate<T, U>
where T : class
where U : class
{
IEnumerable<T> List();
T Get(U id);
}
所以当我这样实现时:
public class TestInterface : IOurTemplate<MyCustomClass, Int32>
{
public IEnumerable<MyCustomClass> List()
{
throw new NotImplementedException();
}
public MyCustomClass Get(Int32 testID)
{
throw new NotImplementedException();
}
}
我收到错误消息:类型“int”必须是引用类型才能将其用作泛型类型或方法“TestApp.IOurTemplate”中的参数“U”
我试图推断类型 Int32?,但同样的错误。有任何想法吗?