【发布时间】:2012-10-21 16:12:57
【问题描述】:
谁能教我如何在 C# 中按字母顺序将项目插入列表中?
所以每次我添加到列表中时,我想按字母顺序添加一个项目,理论上列表可能会变得非常大。
示例代码:
Public Class Person
{
public string Name { get; set; }
public string Age { get; set; }
}
Public Class Storage
{
private List<Person> people;
public Storage
{
people = new List<Person>();
}
public void addToList(person Person)
{
int insertIndex = movies.findindex(
delegate(Movie movie)
{
return //Stuck here, or Completely off Track.
}
people.insert(insertIndex, newPerson);
}
}
【问题讨论】:
-
在这个 Stackoverflow 中:stackoverflow.com/questions/188141/…
-
@John3136 在合适的位置插入和每次插入后重新排序列表是不一样的。
-
使用专门的集合 - 例如排序列表。 List.Insert 在 LOC、错误、cpu、内存、程序员时间等方面并不是一个有效的解决方案。
-
Kirk - 我看不出我建议它在哪里。我的目的是找到现有的排序集合类之一,而不是找出如何对集合进行排序。