最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何通过对象属性之一对对象的ArrayList进行排序?

SEO心得admin75浏览0评论
本文介绍了如何通过对象属性之一对对象的ArrayList进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何通过对象属性之一对对象的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());
发布评论

评论列表(0)

  1. 暂无评论