Linq查询列出VB.NET [英] Linq query to list VB.NET

查看:124
本文介绍了Linq查询列出VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim query = From o In myContainer.MyObjects Select o.MyStringProperty Distinct

Dim myProperties As List(Of String) = query.ToList????? 'no way!!!'

查询"类型为IEnumerable(字符串)

"query" type is IEnumerable(Of String)

我试图直接将query用作(基础设施)组合框的数据源,但它抛出NullReferenceException,因此我决定将其转换为字符串列表,以成为更经典"的数据源.

I tried to use the query directly as a DataSource of a (infragistic) combobox, but it throws me NullReferenceException, so I decided to convert it to a listof strings, to be a more "classical" datasource.

Dim values As List(Of String) = query.AsQueryable().ToList()

也不起作用:类型'System.Collections.Generic.List(Of System.Linq.IQueryable(Of String))'的值不能转换为'System.Collections.Generic.List(Of String )'.

推荐答案

最后,使用旧方法解决了:)

Finally, solved with good old method : )

  Dim values As New List(Of String)

  For Each item In query
    values.Add(item)
  Next item

这篇关于Linq查询列出VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆