使用Linq在VB.NET中获取ID列表(字符串)

JTu*_*ney 0 linq vb.net

我有一个IList(Of Customer)和Linq我试图将每个customerId添加到类型字符串列表中.

这是我认为会起作用但它不会:

Dim s As List(Of String) = (From c In customers Select c.Id).ToList(Of String)
Run Code Online (Sandbox Code Playgroud)

D S*_*ley 5

您不能仅使用不同的泛型参数隐式转换类型ToList.您必须使用演员表或投影进行转换.

只需用作ToString项目字符串:

Dim s As List(Of String) = (From c In customers Select (c.Id.ToString())).ToList()
Run Code Online (Sandbox Code Playgroud)