根据对象中的属性查找重复项 [英] Finding Duplicates based On A Property In Object

查看:57
本文介绍了根据对象中的属性查找重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据对象中的字段检查重复项.

I want to check for duplicates based on a field in an object.

我有一个名为Item的对象,该对象具有3个属性

I have an object called Item that has 3 properties

ID
Rank
Name

我在一个名为

lstTheItems

我正在使用此代码检查重复项

I am using this code to check for duplicates

'lstTheItems IS NOT CORRECT
 Dim duplicates = lstTheItems.GroupBy(Function(i) i) _
                                .Where(Function(g) g.Count() > 1) _
                                .[Select](Function(g) g.Key)

如何基于Name属性返回重复项?

How do I return duplicate items base on the Name property?

推荐答案

Dim duplicates = svgGrpContainer.Select(Function(x) svgGrpContainer.Count(Function(y)) > 1));

这意味着我们将选择svgGrpContainer中出现多次的所有元素.

This means that we will select all the elements which appear more than once in the svgGrpContainer.

Function(x) = svgGrpContainer的一个元素

Function(x) = one element of svgGrpContainer

svgGrpContainer.Count =遍历所有获得计数的元素.

svgGrpContainer.Count = go through all the elements getting the count of..

Function(y) > 1 =表示我们将所有出现一次以上的所有元素

Function(y) > 1 = means that we will take all the element which appear more than once

我希望这对您有帮助

这篇关于根据对象中的属性查找重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆