在我的项目中,我遇到了一个关键问题:我有一个集合中所有Employee
s 的集合。一些Employee
s 具有相同的LName
:
public class Employee
{
public int ID { get; set; }
public string FName { get; set; }
public string MName { get; set; }
public string LName { get; set; }
public DateTime DOB { get; set; }
public char Gender { get; set; }
}
public class MyClass
{
public List<Employee> GetAll()
{
List<Employee> empList = new List<Employee>();
empList.Add(new Employee()
{
ID = 1,
FName = "John",
MName = "",
LName = "Shields",
DOB = DateTime.Parse("12/11/1971"),
Gender = 'M'
});
empList.Add(new Employee()
{
ID = 2,
FName = "Mary",
MName = "Matthew",
LName = "Jacobs",
DOB = DateTime.Parse("01/17/1961"),
Gender = 'F'
});
empList.Add(new Employee()
{
ID = 3,
FName = "Amber",
MName = "Carl",
LName = "Agar",
DOB = DateTime.Parse("12/23/1971"),
Gender = 'M'
});
empList.Add(new Employee()
{
ID = 4,
FName = "Kathy",
MName = "",
LName = "Foxsss",
DOB = DateTime.Parse("11/15/1976"),
Gender = 'F'
});
empList.Add(new Employee()
{
ID = 5,
FName = "Lena",
MName = "Ashco",
LName = "Bilton",
DOB = DateTime.Parse("05/11/1978"),
Gender = 'F'
});
empList.Add(new Employee()
{
ID = 6,
FName = "Susanne",
MName = "",
LName = "Buck",
DOB = DateTime.Parse("03/7/1965"),
Gender = 'F'
});
empList.Add(new Employee()
{
ID = 7,
FName = "Jim",
MName = "",
LName = "Hooks",
DOB = DateTime.Parse("09/11/1972"),
Gender = 'M'
});
empList.Add(new Employee()
{
ID = 8,
FName = "Jane",
MName = "G",
LName = "Hooks",
DOB = DateTime.Parse("12/11/1972"),
Gender = 'F'
});
empList.Add(new Employee()
{
ID = 9,
FName = "Robert",
MName = "",
LName = "Fox",
DOB = DateTime.Parse("06/28/1964"),
Gender = 'M'
});
empList.Add(new Employee()
{
ID = 10,
FName = "Cindy",
MName = "Preston",
LName = "Fox",
DOB = DateTime.Parse("01/11/1978"),
Gender = 'M'
});
return empList;
}
}
LName
如何使用 LINQ 从我的集合中获取重复记录(基于)?