copy SortedList

  • Thread starter Thread starter aeshiels
  • Start date Start date
A

aeshiels

Hello,

I have a SortedList defined as...

SortedList<CUser, CUser> userList = new SortedList<CUser,
CUser>();

....and which to copy it to another sorted list

SortedList<CUser, CUser> userList2 = new SortedList<CUser,
CUser>();

What is the easiest way to do this without iterating through the list
and copying each indiviual item to the new array?

Im a C++ developer and use stl::copy to copy my vectors etc. and was
wondering anything similar in C# (ive had a look on google but didnt
find anything as yet).

Any help would be appreciated. Thanks

Andy.S
 
Thanks Greg. Ill try that.

Is there another method of copying a SortedList without having to pass
the list via the constructor?

Thanks
Andy
 
Don't think so but someone may have another way .. I have added an extension
method to mine for this.

Cheers,

Greg
 
Thanks Greg. Ill try that.

Is there another method of copying a SortedList without having to pass
the list via the constructor?

If you are familiar with the STL, you might want to take a look at the
open source CSTL library. In CSTL, you could do this:

SortedList<int,string> slist = new SortedList<int,string>();
slist[4] = "hello";
slist[2] = "world";
slist[5] = "bob";

SortedList<int, string> copy = new SortedList<int,string>();
Algorithm.Copy(slist, IteratorUtil.BackInserter(copy));

Granted, in this case, it would have been easier to use the copy
constructor, but you get the idea.

http://sourceforge.net/projects/cstl

H^2
remove . bounce
 
Back
Top