There is no implicit reference conversion from 'dungGene
本文关键字:dungGene from conversion is no implicit reference There | 更新日期: 2023-09-27 18:03:30
好吧,我遵循了许多教程使其工作,但我从来没有找到一个解决方案。
我在静态类中有这个函数:
public static bool isDifferent<T>(List<T> list1, List<T> list2) where T : IComparable
{
foreach (T item1 in list1)
{
bool different = false;
foreach (T item2 in list2)
{
if (item2.CompareTo(item1) != 0)
different = true;
else
{
different = false;
break;//fuck yes i will use a break
}
}
if (different)
return true;
}
return false;
}
可以很好地处理int类型的列表但是现在我想比较一个名为room的自定义类的列表。
我的类声明有所有需要的:public class Room: IComparable
和我添加了CompareTo函数
public int CompareTo(Room other)
{
if (other == null) return 1;
if (Methods.isDifferent(doors, other.doors))
return 1;
else
return 0;
}
所以,每个房间都有一个走廊id列表,这是我需要比较的唯一值。
我看了很多教程,他们似乎和我的结构一样。
您的问题是Room
实现了IComparable<Room>
,这与IComparable
的接口不同。你应该把你的方法更新为:
public static bool isDifferent<T>(List<T> list1, List<T> list2) where T : IComparable<T>
从您的问题中,我可以推断出您实现了接口IComparable<<strong>Room>
但是,接口IComparable
实现IComparable,声明方法"public int CompareTo(object other)"。