-3
的名单上有以下接口:接口,具有相同的接口
public interface IObject{
double x {get;}
double y {get;}
List<IObject> List{get; set;}
}
这个类
public class Holder<T> where T : IObject {
private T myItem;
public void ChangeItemList(T item){
myItem.List = item.List;
}
但是编译器不喜欢在这条线的ChangeItemList方法:
myItem.List = item.List;
给我这个错误:
Cannot convert source type 'List<T>' to target type 'List<IObject>'
为什么我不能做到这一点,什么是这种情况下的一个很好的解决方案? 谢谢
您不可能拥有该接口,因为接口不能包含字段。这段代码不会编译。 – Jon
您的界面似乎有成员字段。这是不允许的。双x;和双y;不能在接口中声明。 – Baldrick
我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 –