List<list> ListA = new List<list>();
ListA.Add(new list() { Date = PlayerDate, Name = PlayerName, Scorer = PlayerLe });
lvTeamA.ItemsSource =
public class list
{
public string Date { get; set; }
public string Name { get; set; }
public string Scorer { get; set; }
}
如何检查PlayerName
中是否已存在ListA
,以便我可以阻止再次添加数据?
答案 0 :(得分:3)
您可以使用.Any()方法。
if(ListA.Any(l => l.Name == "player name")) {
// it's already added...
}