Hi.

I want to compare two arraylists with each other, but not with the compare method.
The problem is that i am using .net remoting, and i gotta keep a clients arraylist updated. And it would be a waste of bandwith to send the arraylist as an object over to the server to compare it.

So is it possible to compare collections this way? MD5? Hash value? Checksum? Whatever! :)

Or are there any easier way around this problem? :icon_rolleyes:

Thanks alot!

That depends on what type of underlying objects they are. If you don't implement IComparable then I believe the CLR compares the return value of .GetHasCode() . Why not just implement IComparable...?

I am new to C#, so please bare over with me ;)

As far as I can see, IComparable doesent do the job.

My problem is, that I have, lets say 2 computers running this application with each of their own arraylist (or kind of collection). Instead of sending the arraylist from one of the machines to the other (would be a large data transfer if the array is big), I would like to calculate some kind of value based on the array and its contents. The value should of course be the same no matter what machine it is calculated on, as long as the contents are the same.
Im not quite sure yet, but I believe that the list will contain strings.

Ive tried .GetHashCode(), but it returns the same value no matter how many and what objects are in it :(

How about you post the relevant code and explain what data is in the ArrayList, and how it is represented? You can override GetHashCode() to make it any value for your class.

The code is not written yet, I am just thinking about a way to solve the problem.
Yea I guess I could override it, or make my own method, that in some easy way calculates a value..

For this specific mechanism, you could make a function that converts your ArrayList to a byte[] and then passes that through an MD5 or SHA1 algorithm or whatnot. See System.Security.Cryptography.SHA1, for example.

You should not rely on the behavior of GetHashCode being consistent on different computers unless you can find documentation guaranteeing that its behavior is. Also, GetHashCode is a hash function that produces duplicate hash codes for different values -- it's not a cryptographically strong hash, the way that SHA1 or MD5 are, which means the probability of getting two values that have the same hash is (in the long run) very high.

There are other ways to solve this problem that don't use hashes. You can keep a version number instead (every time you change the array list, you have to increment the version number) -- if the version number hasn't changed, then the clients don't need to be updated. I don't know how .NET remoting works; another way to send information about the ArrayList is to send a description of how the ArrayList has changed -- using some kind of tuple that says things like "insert blah at index 23" and "remove item at index 14". I don't know how .NET remoting works; you might want to investigate the possibility that it does this kind of thing (version numbers or hashing especially) automatically.

I think I´ll go with the versioning. Why the ... didnt I think of that to start with!

Thanks alot! :)

This question has already been answered. Start a new discussion instead.