的内部场列表
class Pin
{
string Name; //can be either Numerical or AlphaNum
}
enum Place
{
Left,
Right
}
class Map
{
Pin pin;
Place Place;
Rectangle Rect;
}
的Pin
的Name
字段中的代码可以是仅数字或字母数字,让我去由串来支持这两者。
现在我的问题是,如果我有一个List<Map>
我怎么能按Pin的名字字段排序这个列表?我试过下面的代码,但它无法编译:
map.Sort((x, y) => x.Pin.Name.CompareTo(y.Pin.Name));
//Cannot implicitly convert type 'void' to 'System.Collections.Generic.List<DataModels.PinMap>
看看http://stackoverflow.com/questions/3163922/sort-a-custom-class-list – Tomtom
你有什么实际看起来不错......?你确定你的真实代码不是'map = map.Sort(...);'? –
听起来就像你试图设置地图等于调用Sort的结果。跳过(排序会重新排列列表中的元素)或使用map = map.OrderBy(x => x.pin.Name).ToList(); – mlorbetske