0

我想在我的 VB.NET 代码中使用Enumerable.DistinctBy()Method *。但我遇到了'DistinctBy()' is not member of System.Collections.Generic.IEnumerable(Of CustomClass)错误。

这就是我的代码的样子:

Dim AllComponentDocuments As List(of CustomClass)

AllComponentDocuments = AllComponentDocuments.DistinctBy(Function(obj) obj.Path).ToList()

当我用DistinctBy()组合替换时GroupBy()First()一切都按预期工作。

AllComponentDocuments = AllComponentDocuments.GroupBy(Function (doc) doc.Path).Select(Function(docs) docs.First).ToList()

为什么可以使用GroupBy()andFirst()而不是DistinctBy()?我在那里缺少什么?

* 事实上,这是 Autodesk Inventor 的 iLogic 代码,但基本上(双关语)它是使用 eval() 运行的 VB.NET 代码。

4

0 回答 0