问题描述
我想根据对象中的字段检查重复项.
我有一个名为 Item 的对象,它有 3 个属性
ID Rank Name
我在一个名为
的容器中有一个 Item 类型的列表lstTheItems
我正在使用此代码检查重复项
'lstTheItems IS NOT CORRECT Dim duplicates = lstTheItems.GroupBy(Function(i) i) _ .Where(Function(g) g.Count() > 1) _ .[Select](Function(g) g.Key)
如何根据 Name 属性返回重复项?
推荐答案
Dim duplicates = svgGrpContainer.Select(Function(x) svgGrpContainer.Count(Function(y)) > 1));
这意味着我们将选择所有在 svgGrpContainer 中出现多次的元素.
Function(x) = svgGrpContainer 的一个元素
svgGrpContainer.Count = 遍历所有元素,计算...
Function(y) > 1 = 表示我们将取出所有出现多次的元素
希望对你有帮助
问题描述
I want to check for duplicates based on a field in an object.
I have an object called Item that has 3 properties
ID Rank Name
I have a list of type Item in a container called
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)
How do I return duplicate items base on the Name property?
推荐答案
Dim duplicates = svgGrpContainer.Select(Function(x) svgGrpContainer.Count(Function(y)) > 1));
This means that we will select all the elements which appear more than once in the svgGrpContainer.
Function(x) = one element of svgGrpContainer
svgGrpContainer.Count = go through all the elements getting the count of..
Function(y) > 1 = means that we will take all the element which appear more than once
I hope this helps