如何通过对象属性之一对对象的ArrayList进行排序?
How do I order an ArrayList of objects by one of the objects attributes?
也请不要建议任何与List<T>有关的技术.对于我当前使用的软件,不可能使用List<T>.
And please do not suggest any technique to do with List<T>. For my current software, using List<T> is out of the question.
推荐答案您需要为您的实体实现IComparer,例如:
You need to implement IComparer for your entity like:
public class MyClassComparer : IComparer<MyClass> { public int Compare(MyClass _x, MyClass _y) { return _x.MyProp.CompareTo(_y.MyProp); } }并将其传递给 ArrayList.Sort 喜欢:
myArrayList.Sort(new MyClassComparer());