String VB.Net-不使用循环从集合中获取项

String VB.Net-不使用循环从集合中获取项,string,vb.net,linq,collections,lambda,String,Vb.net,Linq,Collections,Lambda,我想优化此代码: dim mPolNo as new Collection(Of String) For Each _olap As clsOLAP in cscOLAPs mPolNo.Add(_olap._p1.PolNo) Next (PolNo的数据类型为字符串) 我试着使用这个集合。选择我在谷歌中挖掘的 mPolNo = cscOLAPs.Select(Function(x) x._p1.PolNo.ToString) 但是我遇到了这样的错误: Unable to cas

我想优化此代码:

dim mPolNo as new Collection(Of String)
For Each _olap As clsOLAP in cscOLAPs
     mPolNo.Add(_olap._p1.PolNo)
Next
(PolNo的数据类型为字符串)

我试着使用这个集合。选择我在谷歌中挖掘的

mPolNo = cscOLAPs.Select(Function(x) x._p1.PolNo.ToString)
但是我遇到了这样的错误:

Unable to cast object of type 'WhereSelectEnumerableIterator`2[SIPLib.ING.clsOLAP,System.String]' to type 'System.Collections.ObjectModel.Collection`1[System.String]'.

其中
返回
IEnumerable(字符串)

要将其分配给
集合(字符串)
,您需要枚举
Where
的结果

可以通过调用
.ToList()
扩展方法来完成

cscOLAPs.Select(Function(x) x._p1.PolNo.ToString).ToList()

ToList()
可以使用,因为
Collection(Of String)
实现了
IList(Of String)
接口。

谢谢!我需要将mPolNo的数据类型从Collection(of String)更改为List(of String)以使其运行。