誰でも助けてもらえますか、ソートに問題があります。ソートしたと思っていましたが、機能していないようです。
次の値を格納するリストがあります
8,6,10,11,7
私はまた別のリストを持っています(私のクラスのアクセサリーには現在accessoriesIdというプロパティがあり、クラスは現在6,7,8,10,11であるidの順序になっています)
したがって、それらを 6,7,8,10,11 から、8,6,10,11,7 という単純なリストから使用される順序に並べ替える必要があります。
私は icomparable を持っており (以下を参照)、このように呼び出しています - 入りますが、リストにはまだすべてのクラスが含まれていますが、まだ 6,7,8,10,11 の順序になっているため、何かが間違っています。
// accesories is the IList<Accessories> (hence why i am use ToList)
// and sortOrder is the simple int list list<int>
accesories.ToList().Sort(new ItemTpComparer(sortOrder));
class ItemTpComparer : IComparer<Accessories>
{
private IList<int> otherList;
public ItemTpComparer(IList<int> otherList)
{
this.otherList = otherList;
}
#region IComparer<Accessories> Members
public int Compare(Accessories x, Accessories y)
{
if (otherList.IndexOf(x.AccessoryId) > otherList.IndexOf(y.AccessoryId))
return 1;
else if (otherList.IndexOf(x.AccessoryId) < otherList.IndexOf(y.AccessoryId))
return -1;
else
return 0;
// tried below also didn't work
//return otherList.IndexOf(x.AccessoryId) - otherList.IndexOf(y.AccessoryId);