Vb.net 将Datatable转换为可枚举到列表(字符串)

Vb.net 将Datatable转换为可枚举到列表(字符串),vb.net,linq,tolist,Vb.net,Linq,Tolist,我在下面的代码行中有datatable dt: Dim str As List(Of String) = dt.AsEnumerable().Select(Function(a) New With {.WorkZone = a.Field(Of String)("MarkerWorkZone")}).ToList() ToString是作为select语句的一个选项提供的,但我收到了错误:值类型“List(Of)”无法转换为“List(Of String)”。 虽然我知道

我在下面的代码行中有datatable dt:

Dim str As List(Of String) = dt.AsEnumerable().Select(Function(a) New With {.WorkZone = a.Field(Of String)("MarkerWorkZone")}).ToList() 
ToString是作为select语句的一个选项提供的,但我收到了错误:值类型“List(Of)”无法转换为“List(Of String)”。 虽然我知道我确实在尝试转换EnumerablerRowCollection

也就是说,我能够将类似的代码行转换为字典:

Dim di As Dictionary(Of String, String) = dt.AsEnumerable().Select(Function(a) New With {.Code = a.Field(Of String)("AssemblyCode"), .DeficiencyDesc = a.Field(Of String)("AssemblyDeficiencyDesc")}).Distinct().ToDictionary(Function(x) x.Code, Function(x) x.DeficiencyDesc)
但是toList()没有添加函数的选项,ToDictionary也没有添加函数的选项


我在托利斯的声明中遗漏了什么?是否可以转换为列表?

您正在Select()转换中创建一个匿名对象。只要选择
a.Field(字符串)(“MarkerWorkZone”)
你就有了一个
列表
。你也可以写一些愚蠢的东西,比如
。。。dt.AsEnumerable().Select(函数(a)New With{.WorkZone=a.Field(字符串)(“MarkerWorkZone”)}.WorkZone).ToList()
:)@Jimi谢谢!这起作用了(我试过你的第二个评论)。现在我需要回到过去,确切地理解为什么这样做。好吧,当您将收件人声明为
列表(字符串)
时,您在那里得到的将返回一个
列表(a')
(匿名对象)。另一个to方法都选择一个字符串,最后累积到一个列表中。@Jimi的答案是最好的。但我也使用了foreach将数据从数据表移动到列表(或哈希集等)。如果存在某些条件,或者数据表中有多个字段,则使用foreach编写代码可能更容易。