的內部場列表
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