Bitte beachten Sie den Code unten:Enumerable.tolist Rückkehr eine generische Liste
Public Shared Sub LinqTest()
Dim t1 As New TestPerson
t1.id = 1
t1.name = "Ian"
Dim t2 As New TestPerson
t2.id = 2
t2.name = "Lauren"
Dim list As List(Of TestPerson) = New List(Of TestPerson)
list.Add(t1)
list.Add(t2)
Dim list2 As List(Of TestPerson) = New List(Of TestPerson)
list2.Add(t1)
Dim linqresult = From p1 In list Join p2 In list2 On New With {Key p1.id, Key p1.name} Equals New With {Key p2.id, Key p2.name} Select p1.id, p1.name
End Sub
Ich weiß, ich kann dies tun:
Dim list3 As New List(Of TestPerson)
For Each var In test
Dim tyPerson As New TestPerson
tyPerson.id = var.id
tyPerson.name = var.name
list3.Add(tyPerson)
Next
Ist es möglich, mit einer generischen Liste zu verwenden .ToList?
Update Folgend auf Ed Plunketts Kommentar; Ich habe dies versucht:
Dim linqresult As List(Of TestPerson) = test.ToList
Der Compiler Fehler ich erhalte, ist:
Value of type 'System.Collections.Generic.List(Of <anonymous type>)' cannot be converted to 'System.Collections.Generic.List(Of com.Genie.PresentationLayer.Console.TestPerson)
ich auch schon versucht, diese haben:
Dim linqresult = test.ToList
For Each var As TestPerson In linqresult
Next
Der Fehler, den ich bekommen ist:
Value of type '<anonymous type> (line 36)' cannot be converted to 'com.Genie.PresentationLayer.Console.TestPerson
'linqresult = linqresult.ToList' –
@Ed Plunkett, ich glaube nicht, dass Linqresult eine generische Liste in Ihrem Beispiel wäre? – w0051977
Was ist passiert, als Sie es versucht haben? –