serializer
Programmer
I am using the code below. The code that is commented out is when I don't use the generic CompareTo which works. This code gives me error: Failed to compare two elements in the array.
Why does this happen? I would rather use the Generic one.
private void Form1_Load(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(new POrder());
POrder p2 = new POrder();
p2.Order = 1;
arr.Add(p2);
arr.Sort();
foreach (POrder p in arr)
{
Console.WriteLine(p.Order.ToString());
}
}
}
public class POrder : IComparable<POrder>
{
public int Order = 2;
//#region IComparable Members
//public int CompareTo(object obj)
//{
// POrder emp = (POrder)obj;
// return Order.CompareTo(emp.Order);
//}
//#endregion
#region IComparable<POrder> Members
public int CompareTo(POrder other)
{
return Order.CompareTo(other.Order);
}
#endregion
}
Why does this happen? I would rather use the Generic one.
private void Form1_Load(object sender, EventArgs e)
{
ArrayList arr = new ArrayList();
arr.Add(new POrder());
POrder p2 = new POrder();
p2.Order = 1;
arr.Add(p2);
arr.Sort();
foreach (POrder p in arr)
{
Console.WriteLine(p.Order.ToString());
}
}
}
public class POrder : IComparable<POrder>
{
public int Order = 2;
//#region IComparable Members
//public int CompareTo(object obj)
//{
// POrder emp = (POrder)obj;
// return Order.CompareTo(emp.Order);
//}
//#endregion
#region IComparable<POrder> Members
public int CompareTo(POrder other)
{
return Order.CompareTo(other.Order);
}
#endregion
}