How to use Collection.CopyTo?
-
.NET newbie question I have a Collection object that I would like to copy into another collection object. The collection is of type: System.Collections.ObjectModel.Collection The Collection.CopyTo method requires that I provide an array and an index. The question is: How do I syntactically express the array portion of the target collection. I can't do this, because param 1 is a Collection: Collection1.CopyTo(Collection2, 0) I hoped I could do something like this to specify the array, but alas no: Collection1.CopyTo(Collection2[], 0) Is there a way I can do this or do I have to enumerate the contents of Collection1 and Add to Collection2? Thanks
-
.NET newbie question I have a Collection object that I would like to copy into another collection object. The collection is of type: System.Collections.ObjectModel.Collection The Collection.CopyTo method requires that I provide an array and an index. The question is: How do I syntactically express the array portion of the target collection. I can't do this, because param 1 is a Collection: Collection1.CopyTo(Collection2, 0) I hoped I could do something like this to specify the array, but alas no: Collection1.CopyTo(Collection2[], 0) Is there a way I can do this or do I have to enumerate the contents of Collection1 and Add to Collection2? Thanks
Well, you could always do
Collection2.Clear();
Collection2.AddRange(Collection1);Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Well, you could always do
Collection2.Clear();
Collection2.AddRange(Collection1);Regards Senthil _____________________________ My Blog | My Articles | WinMacro
No such method (AddRange) on the Collection class.
-
No such method (AddRange) on the Collection class.
My bad. I assumed you were using the List class. Looks like you have no other option other than looping over and copying elements.
Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro
-
My bad. I assumed you were using the List class. Looks like you have no other option other than looping over and copying elements.
Regards Senthil [MVP - Visual C#] _____________________________ My Blog | My Articles | My Flickr | WinMacro
Such is life in .NET. Times like this I miss things like memcpy and void ** :)~