1
我想弄清楚如何將枚舉添加到Linq對象。例如:Linq到XML:將枚舉添加到對象
Dim thingBlock = <Things>
<Thing Name="Ish">
<SmallThing>Jibber</SmallThing>
<SmallThing>Jabber</SmallThing>
</Thing>
<Thing Name="Ugly Guy">
<SmallThing Name="Carl"></SmallThing>
<SmallThing Marks="Marks"></SmallThing>
</Thing>
</Things>
Dim myList As New List(Of Thing)
myList.AddRange(thingBlock.<Thing>.Select(Function(th) New Thing With {.Name = [email protected]}))
Public Class Thing
Public Property Name As String
Public Property SmallThings As New List(Of String)
End Class
這能很好地創造新的Thing
並將它們添加到myList
,但我無法弄清楚如何爲String的IEnumerable的添加到我的SmallThings
名單。例如,這不工作:
myList.AddRange(thingBlock.<Thing>.Select(Function(th) New Thing With {.Name = [email protected], th.Select(Function(st) .SmallThings.Add([email protected])}))
我只是想添加的所有Thing
類的<SmallThing>[email protected]
到SmallThings
財產。
完美,這是'.ToList'奏效。好東西! – 2010-10-02 06:30:46