I am setting the items which i want to Remove from list as null and then sorting list through IComparable method CompareTo so that null items would be at the top … then using RemoveRange function on list but unable to so so … i see no problem in following code:
try
{
foreach (Invoice item in inv)
{
if (item.qty == 0)
{
item.CustomerName = null;
item.qty = 0;
i++;
}
}
inv.Sort();
inv.RemoveRange(0, i);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
#region IComparable<Invoice> Members
public int CompareTo(Invoice other)
{
return this.CustomerName.CompareTo(other.CustomerName);
}
#endregion
error occurs at inv.RemoveRange(0,i); saying that :Failed to compare two elemets in array
Why is it so??
or