I’m having a issue sorting an arraylist of custom objects by a string field.
This is the code I’m trying to do:
arrRegion.Sort(delegate(Portal.Entidad.Region x, Portal.Entidad.Region y)
{
return x.RegNombre.CompareTo(y.RegNombre);
});
But I’m getting this error:
Argument type 'anonymous method' is not assignable to parameter type 'System.Collection.IComparer'
What am I missing?
Maybe you should use the extension methods provided in System.Linq namespace:
If you have control over the original ArrayList and you can change its type to a typed list like this
List<Portal.Entidad.Region>, I would suggest you do it. Then you would not need to cast everything afterward and can sort like this: