抱歉,如果之前有人问过这个问题,但实际上不可能用谷歌搜索。我认为 int 数组实现了 IEnumerable,因此 Thing 应该能够实现 IThing。怎么没有呢?
public interface IThing
{
IEnumerable<int> Collection { get; }
}
public class Thing : IThing
{
public int[] Collection { get; set; }
}
注意
public class Thing : IThing
{
public int[] Array { get; set; }
public IEnumerable<int> Collection
{
get
{
return this.Array;
}
}
}
is fine.
对于要实现的接口,方法签名和返回类型必须相同,因此 int[] 可转换为 IEnumerable 的事实恐怕没有什么区别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)