How-to Compare 2 arraylists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

What is the best way to compare 2 (large) ArrayLists filled with an object.
Can you please help me?

Gaby
 
Hi,

What you mean with "filled with an object" ?

If the array is of a user defined type I th ink that first it depend of how
you want it to compare them, you could compare if both arrays have the same
references, if so all you have to do is a foreach.

If you want to compare the objects itself it depend of the class.

Also remember to check for the size to be equal.


cheers,
 
Hi,

I need to compare 2 array lists with the same object type (cAddress).
public class cAddress
{
public string Address = "";
public string Number = "";
public string Zip = "";
public string City = "";
public string Country = "";
public string Telephone = "";
}

Every period the data from the database will be checked against the current
arraylist.
The lists will be filled with aprox 10000 objects.
No I want to know what the best and quickest way is.

Gaby
 
First step, make cAddress objects comparable. Basically, this means to
implement the IComparable interface (that is, define a CompareTo method for
it). You may also wnat to define an operator== for it.

Next, I'm going to assume that Current corresponds to Database, in
which case it, it's just:

for(int i =0; i< Current.Length, ++i)
{
cAddress ad1 = Current;
cAddress ad2 = Database;
if (ad1.CompareTo(ad2) != 0)
return "Don't Match";
}
return "Match";

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
 
cheers....

James Curran said:
First step, make cAddress objects comparable. Basically, this means to
implement the IComparable interface (that is, define a CompareTo method for
it). You may also wnat to define an operator== for it.

Next, I'm going to assume that Current corresponds to Database, in
which case it, it's just:

for(int i =0; i< Current.Length, ++i)
{
cAddress ad1 = Current;
cAddress ad2 = Database;
if (ad1.CompareTo(ad2) != 0)
return "Don't Match";
}
return "Match";

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Gaby said:
Hi,

I need to compare 2 array lists with the same object type (cAddress).
public class cAddress
{
public string Address = "";
public string Number = "";
public string Zip = "";
public string City = "";
public string Country = "";
public string Telephone = "";
}

Every period the data from the database will be checked against the current
arraylist.
The lists will be filled with aprox 10000 objects.
No I want to know what the best and quickest way is.

Gaby
 
Back
Top