1、List
List<string> temp = new List<string>(); foreach (PlayAgentItem arg in PlayAgentConfigSection.values.Cast<PlayAgentItem>()) { temp.Add(arg.IpAddr); } temp = temp.OrderBy(u => u).ToList();
2、Dictionary
private Dictionary<IPAddress, Seat> SeatList; SeatList.OrderBy(r => r.Value.ID).ToDictionary(r => r.Key, r => r.Value)
Seat类要实现IComparable的CompareTo接口
public class Seat, IComparable<Seat>
{
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public int CompareTo(Seat obj)
{
if (this.ID == obj.ID)
{
return 0;
}
else if (this.ID > obj.ID)
{
return 1;
}
else
{
return -1;
}
}
}