copy SortedList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aeshiels@gmail.com

    copy SortedList

    Hello,

    I have a SortedList defined as...

    SortedList<CUse r, CUseruserList = new SortedList<CUse r,
    CUser>();

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

    SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
    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

  • Greg Young

    #2
    Re: copy SortedList

    Since you are just creating a clone of the first I would probably use


    SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
    CUser>(userList 1);

    Cheers,

    Greg

    <aeshiels@gmail .comwrote in message
    news:1160390047 .467788.309270@ e3g2000cwe.goog legroups.com...
    Hello,
    >
    I have a SortedList defined as...
    >
    SortedList<CUse r, CUseruserList = new SortedList<CUse r,
    CUser>();
    >
    ...and which to copy it to another sorted list
    >
    SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
    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
    >

    Comment

    • aeshiels@gmail.com

      #3
      Re: copy SortedList

      Thanks Greg. Ill try that.

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

      Thanks
      Andy



      Greg Young wrote:
      Since you are just creating a clone of the first I would probably use

      >
      SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
      CUser>(userList 1);
      >
      Cheers,
      >
      Greg
      >
      <aeshiels@gmail .comwrote in message
      news:1160390047 .467788.309270@ e3g2000cwe.goog legroups.com...
      Hello,

      I have a SortedList defined as...

      SortedList<CUse r, CUseruserList = new SortedList<CUse r,
      CUser>();

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

      SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
      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

      Comment

      • Greg Young

        #4
        Re: copy SortedList

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

        Cheers,

        Greg
        <aeshiels@gmail .comwrote in message
        news:1160392709 .673450.173570@ m73g2000cwd.goo glegroups.com.. .
        Thanks Greg. Ill try that.
        >
        Is there another method of copying a SortedList without having to pass
        the list via the constructor?
        >
        Thanks
        Andy
        >
        >
        >
        Greg Young wrote:
        >Since you are just creating a clone of the first I would probably use
        >http://msdn2.microsoft.com/en-us/library/ms132324.aspx
        >>
        >SortedList<CUs er, CUseruserList2 = new SortedList<CUse r,
        >CUser>(userLis t1);
        >>
        >Cheers,
        >>
        >Greg
        >>
        ><aeshiels@gmai l.comwrote in message
        >news:116039004 7.467788.309270 @e3g2000cwe.goo glegroups.com.. .
        Hello,
        >
        I have a SortedList defined as...
        >
        SortedList<CUse r, CUseruserList = new SortedList<CUse r,
        CUser>();
        >
        ...and which to copy it to another sorted list
        >
        SortedList<CUse r, CUseruserList2 = new SortedList<CUse r,
        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
        >
        >

        Comment

        • Harold Howe

          #5
          Re: copy SortedList

          aeshiels@gmail. com wrote:
          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, stringslist = new SortedList<int, string>();
          slist[4] = "hello";
          slist[2] = "world";
          slist[5] = "bob";

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

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

          Download CSTL for free. CSTL is a port of the C++ STL to C# 2.0 and .NET. The library utilizes C# generics, anonymous methods, and enumerable iterators, while alleviating some of C#'s deficiencies (no C++ templates, limited operator overloading, no C++ style iterators, etc).


          H^2
          remove . bounce

          Comment

          Working...