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

2026-05-06 08:571阅读0评论SEO问题
  • 内容介绍
  • 文章标签
  • 相关推荐

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

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 an object of type 'String' to type 'List(Of String)'.

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

VB.NET中为何基础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 正如它所述,你正试图将迭代器存储在列表中.

试试这个:

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

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

标签:Linq查询

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

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 an object of type 'String' to type 'List(Of String)'.

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

VB.NET中为何基础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 正如它所述,你正试图将迭代器存储在列表中.

试试这个:

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

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

标签:Linq查询