c#generics - 公共类MyContainer其中T:class,IComparable [英] c# generics - public class MyContainer where T: class, IComparable

查看:83
本文介绍了c#generics - 公共类MyContainer其中T:class,IComparable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是真的吗?请证明

公共类MyContainer< t>其中T:class,IComparable

{



}

I. MyContainer类要求泛型参数实现IComparable接口。

II。编译器将报告该代码块的错误。 - 错误

III。 MyContainer泛型参数定义有多个约束。 -True

IV。 MyContainer类要求泛型参数是引用类型,并且还实现了IComparable接口。



我尝试了选项2和3.但是不要为1和4。澄清

which are true? Please justify
public class MyContainer<t> where T: class, IComparable
{

}
I. MyContainer class demands that the generic parameter implements IComparable interface.
II. The compiler will report an error for that code block. - False
III. There are multiple constraints on MyContainer generic parameter definition. -True
IV. MyContainer class demands that the generic parameter is of reference type and also implements the IComparable interface.

I tried for option 2 and 3. But donno for 1 and 4. Please clarify

推荐答案

4是真的。

我将留给你的理由,因为这是你的功课!
4 is true.
The reasoning I will leave to you, since it is your homework!


这篇关于c#generics - 公共类MyContainer其中T:class,IComparable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆