'Read RESX file and returns a List(Of ResXDat开发者_开发问答aNode)
Dim allNodes = getResourceData()
'Linq Query to extract the nodes
Dim movedNodes = From rowNodes In allNodes _
Where rowNodes.Comment = oldRowNumber _
Select rowNodes
Will this:
Dim nodesToMove As List(Of ResXDataNode) = New List(Of ResXDataNode)
For Each movedNode As ResXDataNode In movedNodes
nodesToMove.Add(movedNode)
Next
or
Dim nodesToMove As List(Of ResXDataNode) = movedNodes.ToList
Provide two separate copies of the node? Or will the List and Linq query still be referencing the same data?
They will still refer to the same objects - that won't create any extra ResXDataNode
objects.
By the way, calling movedNodes.ToList()
would be simpler than manually adding each one...
Now it's perfectly possible that each time you iterate over movedNodes
it might create new objects - it really depends on what it's doing, and you haven't shown how it's being created. But copying to the list doesn't create new objects.
If ResXDataNode
is a reference type they still will be referencing the same objects, if it is a value type a copy is created and added to the new list.
Edit: ResXDataNode
is a reference type, so the new list will still refer to the same objects.
精彩评论