Compare SortedList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Esser

    Compare SortedList

    Hi,

    if there are two objects of type "SortedList ", how can I compare them?
    I want to find out whether they have exactly the same values and keys in the
    same sort order but I do not want to loop through all.

    By the way: how can I make a real/deep copy of a sorted list?


  • Joanna Carter \(TeamB\)

    #2
    Re: Compare SortedList

    "Frank Esser" <Mistral@nurfue rspam.de> a écrit dans le message de news:
    e$QCoqAcFHA.139 2@TK2MSFTNGP14. phx.gbl...
    [color=blue]
    > if there are two objects of type "SortedList ", how can I compare them?
    > I want to find out whether they have exactly the same values and keys in[/color]
    the[color=blue]
    > same sort order but I do not want to loop through all.[/color]

    Whether you write the looping code or you find a class that already does it,
    the only way to achieve any operation on a whole list is to loop through it.

    If you are using C# 2.0 then you can always use the new Predicate<T>
    delegate type to simplify the iteration code.
    [color=blue]
    > By the way: how can I make a real/deep copy of a sorted list?[/color]

    By looping ? :-)

    Joanna

    --
    Joanna Carter
    Consultant Software Engineer


    Comment

    • Howard Swope

      #3
      Re: Compare SortedList


      "Frank Esser" <Mistral@nurfue rspam.de> wrote in message
      news:e$QCoqAcFH A.1392@TK2MSFTN GP14.phx.gbl...[color=blue]
      > Hi,
      >
      > if there are two objects of type "SortedList ", how can I compare them?
      > I want to find out whether they have exactly the same values and keys in
      > the same sort order but I do not want to loop through all.
      >[/color]

      I think any meaningfule comparison of lists will involve comparing the
      members. There is nothing dictating the binary representation of the list
      that would allow you to compare lists as chunks of memory so I would think
      you must loop through the members.
      [color=blue]
      > By the way: how can I make a real/deep copy of a sorted list?
      >[/color]

      I lot would depend on the type of data that you were putting in the list


      Comment

      • KH

        #4
        RE: Compare SortedList

        A quick and easy thing to do up front would be to compare the Count property
        between to collections -- if the Count is not the same they definatly do not
        contain the same key/value pairs.

        Likewise you can compare two instances with the equality operator to
        determine if they are in fact the same object (or you could use
        Object.Referenc eEquals() for the same purpose). If the two references point
        at the same object then they definatly contain the same key/value pairs.

        SortedList a = b = null;

        if (a == b)
        {
        // true
        }
        else if (a.Count != b.Count)
        {
        // false
        }
        else
        {
        // Loop 'em ...
        }


        "Frank Esser" wrote:
        [color=blue]
        > Hi,
        >
        > if there are two objects of type "SortedList ", how can I compare them?
        > I want to find out whether they have exactly the same values and keys in the
        > same sort order but I do not want to loop through all.
        >
        > By the way: how can I make a real/deep copy of a sorted list?
        >
        >
        >[/color]

        Comment

        Working...