Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取具有重复项C#linq的对象列表_C#_Linq_List_Duplicates - Fatal编程技术网

获取具有重复项C#linq的对象列表

获取具有重复项C#linq的对象列表,c#,linq,list,duplicates,C#,Linq,List,Duplicates,我有一个这样的对象列表:- List<EmployeeModel> mList = new List<EmployeeModel>(); mList.Add(new EmployeeModel { Place = "place1", Time = time1, EmployeeName = "abc" }); mList.Add(new EmployeeModel { Place = "place2", Time = time2, Empl

我有一个这样的对象列表:-

List<EmployeeModel> mList = new List<EmployeeModel>();
        mList.Add(new EmployeeModel { Place = "place1", Time = time1, EmployeeName = "abc" });
        mList.Add(new EmployeeModel { Place = "place2", Time = time2, EmployeeName = "abc" });
        mList.Add(new EmployeeModel { Place = "place3", Time = time3, EmployeeName = "abc" });
        mList.Add(new EmployeeModel { Place = "place1", Time = time4, EmployeeName = "abc" });
        mList.Add(new EmployeeModel { Place = "place2", Time = time5, EmployeeName = "pqr" });
        mList.Add(new EmployeeModel { Place = "place3", Time = time6, EmployeeName = "xyz" });
        mList.Add(new EmployeeModel { Place = "place1", Time = time7, EmployeeName = "pqr" });
        mList.Add(new EmployeeModel { Place = "place2", Time = time8, EmployeeName = "xyz" });
        mList.Add(new EmployeeModel { Place = "place3", Time = time9, EmployeeName = "abc" });
这给了我一组按EmployeeName分组的值

我有两个字符串,即
placeString
timeString
,我想根据EmployeeName值组中的不同值(
Time
Place
)来填充它们

大概是这样的:-

EmployeeName - abc
placeString:place1 timeString:time4
placeString:place1 timeString:time2
placeString:place1 timeString:time3
EmployeeName - pqr
placeString:place2 timeString:time5
placeString:place1 timeString:time7

EmployeeName - xyz
placeString:place3 timeString:time6
placeString:place2 timeString:time8

我如何解决这个问题?任何帮助都将不胜感激。

预期结果是什么?很容易输出您想要的结果。只需使用
foreach

foreach(var dup in dups)
{
    Console.WriteLine(String.Format("EmployeeName - {0}", dup.Key));
    foreach(EmployeeModel x in dup)
        Console.WriteLine(String.Format("placeString:{0} timeString:{1}", x.Place, x.Time));});
}

预期的结果是什么?很容易输出您想要的结果。只需使用
foreach

foreach(var dup in dups)
{
    Console.WriteLine(String.Format("EmployeeName - {0}", dup.Key));
    foreach(EmployeeModel x in dup)
        Console.WriteLine(String.Format("placeString:{0} timeString:{1}", x.Place, x.Time));});
}

这与排序有什么关系?如果你在mvc中进行排序,你可以尝试添加一个包含员工姓名、地点和时间的列表。你不必创建匿名类型
new{x.EmployeeName}
只需将其更改为
x.EmployeeName
还有
中的逻辑是什么(x=>x.Skip(1).Any())
?这对我来说毫无意义。@M.kazemAkhgary如果你手里有一张桌子,你想知道你是否还有多张牌,你会数一数所有的牌来得到答案吗?说真的,这都是关于性能或冗余的,否则使用你的逻辑,为什么
Any
all
而不仅仅是
Count
这与排序有什么关系?如果你在mvc中做,你可以尝试添加一个包含员工姓名和地点和时间列表的列表。你不必创建匿名类型
new{x.EmployeeName}
只需将其更改为
x.EmployeeName
还有
中的逻辑是什么(x=>x.Skip(1).Any())
?这对我来说毫无意义。@M.kazemAkhgary如果你手里有一张桌子,你想知道你是否还有多张牌,你会数一数所有的牌来得到答案吗?说真的,这都是关于性能或冗余的,否则使用您的逻辑,为什么
Any
all
而不仅仅是
Count