"Cannot convert to IComparer"
Posted
by Odrade
on Stack Overflow
See other posts from Stack Overflow
or by Odrade
Published on 2009-09-28T13:58:04Z
Indexed on
2010/05/12
10:24 UTC
Read the original article
Hit count: 328
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.
© Stack Overflow or respective owner