我有一个具有以下结构的列表:
public class Amendment{
public string name
public string groupnumber
public string edition
public string destination
}
数据如下
var amendmentOne = new Amendment{
name = "Apple",
groupnumber = "A12345",
edition = "A55600E01"
phonenumber = "2232132123"
}
var amendmentTwo = new Amendment{
name = "Apple",
groupnumber = "AG2222",
edition = "A55600E02"
phonenumber = "2232132123"
}
var amendmentThree = new Amendment{
name = "Apple",
groupnumber = "AG55555",
edition = "A55600E03"
phonenumber = "2232132123"
}
当我遍历列表时,是否有可能以某种方式从列表中获得版本号为A55600E03的列表项?版本号除最后几个字符外都相同,因为它们始终为E [number]
答案 0 :(得分:3)
应该和
一样容易var result = List.Orderby(x => edition).Last();
示例
var list = new List<Amendment>{amendmentThree, amendmentOne, amendmentTwo};
var result = list.OrderBy(x => x.edition).Last();
Console.WriteLine(result.edition);
输出
A55600E03