C# Linq 查找 List<> 集合元素
static void Main(string[] args)
{
List<Student> students = new List<Student>{
new Student {Name="Tom", Score=50},
new Student {Name="Mark", Score=80},
new Student {Name="Alice", Score=70},
};
// 查找条件
var query = from student in students
where student.Name == "Mark"
select student;
// 输出查找结果
foreach (Student item in query)
{
Console.WriteLine(item.Name + " - " + item.Score);
}
Console.Read();
}
class Student
{
/// <summary>
/// 姓名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 分数
/// </summary>
public int Score { get; set; }
}