考虑下面的代码
class Pin
{
string Name; //can be either Numerical or AlphaNum
}
enum Place
{
Left,
Right
}
class Map
{
Pin pin;
Place Place;
Rectangle Rect;
}
' Pin
sName
字段只能是数字或字母数字,所以我通过字符串来支持两者。
现在我的问题是,如果我有一个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>