I have the following IComparer defined for boxed RegistryItem objects:
public class BoxedRegistryItemComparer : IComparer<object>
{
public int Compare(object left, object right)
{
RegistryItem leftReg = (RegistryItem)left;
RegistryItem rightReg = (RegistryItem)right;
return string.Compare(leftReg.Name, rightReg.Name);
}
}
I want to use this to sort an ArrayList of boxed RegistryItems (It really should be a List<RegistryItem
>, but that's out of my control).
ArrayList regItems = new ArrayList();
// fill up the list ...
BoxedRegistryItemComparer comparer = new BoxedRegistryItemComparer();
ArrayList.sort(comparer);
However, the last line gives the compiler error: "Cannot convert from BoxedRegistryItemComparer to System.Collections.IComparer". I would appreciate it if someone could point out my mistake.
BoxedRegistryItemComparer
should implement System.Collections.IComparer
to be used with ArrayList.Sort
. you implemented System.Collections.Generic.IComparer<T>
which is not the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With