如何在VB.NET中高效识别List(Of String)内的重复字符串元素?

2026-05-08 11:433阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计248个文字,预计阅读时间需要1分钟。

如何在VB.NET中高效识别List(Of String)内的重复字符串元素?

我有一个客户列表 List(字符串),我试图找到重复的客户。如果客户数量不等于去重后的列表数量,则使用以下代码:

csharpIf Not customers.Count=customers.Distinct().ToList().Count Then customers=customers.Except(customers.Distinct().ToList())End If

但得到以下异常:06001 System.Collections

原因可能是使用了不正确的语法或方法。以下是修改后的代码:

如何在VB.NET中高效识别List(Of String)内的重复字符串元素?

csharpIf Not customers.Count=customers.Distinct().Count() Then customers=customers.Except(customers.Distinct().ToList()).ToList()End If

我有一个客户List(字符串),我试图找到重复的客户.

If Not customers.Count = customers.Distinct.ToList.Count Then customers = customers.Except(customers.Distinct.ToList) End If

但我得到以下异常:

06001

‘System.Collections.Generic.List`1[System.String]’.

这是在列表中查找重复项的正确方法吗?

customers = customers.GroupBy(Function(m) m) _ .Where(Function(g) g.Count() > 1) _ .Select(Function(g) g.Key).ToList

标签:

本文共计248个文字,预计阅读时间需要1分钟。

如何在VB.NET中高效识别List(Of String)内的重复字符串元素?

我有一个客户列表 List(字符串),我试图找到重复的客户。如果客户数量不等于去重后的列表数量,则使用以下代码:

csharpIf Not customers.Count=customers.Distinct().ToList().Count Then customers=customers.Except(customers.Distinct().ToList())End If

但得到以下异常:06001 System.Collections

原因可能是使用了不正确的语法或方法。以下是修改后的代码:

如何在VB.NET中高效识别List(Of String)内的重复字符串元素?

csharpIf Not customers.Count=customers.Distinct().Count() Then customers=customers.Except(customers.Distinct().ToList()).ToList()End If

我有一个客户List(字符串),我试图找到重复的客户.

If Not customers.Count = customers.Distinct.ToList.Count Then customers = customers.Except(customers.Distinct.ToList) End If

但我得到以下异常:

06001

‘System.Collections.Generic.List`1[System.String]’.

这是在列表中查找重复项的正确方法吗?

customers = customers.GroupBy(Function(m) m) _ .Where(Function(g) g.Count() > 1) _ .Select(Function(g) g.Key).ToList

标签: