Compare SortedList

F

Frank Esser

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?
 
J

Joanna Carter \(TeamB\)

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.

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.

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

By looping ? :)

Joanna
 
H

Howard Swope

Frank Esser said:
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.

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.
By the way: how can I make a real/deep copy of a sorted list?

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

Guest

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.ReferenceEquals() 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 ...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top