VB.NET中为何基础LINQ查询执行失败?

2026-06-11 05:29:08 394阅读 0评论 SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

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

我遗失了一些非常基本的常识,我不知道是什么……我对Linq有一个例外:Dim arch As List(Of String) 'gets archive as String() and casts it as List arch=client.GetArchive().ToList() 'here exception occurs: Cannot cast an object of type 'String' to type 'List(Of String)'.

VB.NET中为何基础LINQ查询执行失败?

我遗漏了一些非常基本的东西,我不知道是什么……我对 Linq有一个例外:

Dim arch As List(Of String) 'gets archive as String() and casts it as List arch = client.GetArchive().ToList() 'here exception occurs: Cannot cast object of type 'WhereSelectListIterator`2'... arch = From a In arch Where a.EndsWith(System.Environment.UserName & ".htm") Select a 正如它所述,你正试图将迭代器存储在列表中.

试试这个:

VB.NET中为何基础LINQ查询执行失败?

arch = arch.where(Function(x)x.EndsWith(System.Environment.UserName & ".htm")).ToList()

我更喜欢扩展linq,但它只是偏好,我的工作原因是因为ToList():)

标签: 基础 vb net

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

我遗失了一些非常基本的常识,我不知道是什么……我对Linq有一个例外:Dim arch As List(Of String) 'gets archive as String() and casts it as List arch=client.GetArchive().ToList() 'here exception occurs: Cannot cast an object of type 'String' to type 'List(Of String)'.

VB.NET中为何基础LINQ查询执行失败?

我遗漏了一些非常基本的东西,我不知道是什么……我对 Linq有一个例外:

Dim arch As List(Of String) 'gets archive as String() and casts it as List arch = client.GetArchive().ToList() 'here exception occurs: Cannot cast object of type 'WhereSelectListIterator`2'... arch = From a In arch Where a.EndsWith(System.Environment.UserName & ".htm") Select a 正如它所述,你正试图将迭代器存储在列表中.

试试这个:

VB.NET中为何基础LINQ查询执行失败?

arch = arch.where(Function(x)x.EndsWith(System.Environment.UserName & ".htm")).ToList()

我更喜欢扩展linq,但它只是偏好,我的工作原因是因为ToList():)

标签: 基础 vb net