hi,
In the simplest form, i have two generic lists and i want to compare if the
elements in each of them exactly match.
list<double> list1 = new list<double>();
list1.AddRange(new double[]{1,2});
list<double> list2 = new list<double>();
list2.AddRange(new double[]{1,2});
list1 == list2 returns false
Can someone point me to the right direction.
TIA
Irfan
Nicole Calinoiu - 02 Jan 2007 19:33 GMT
The equality operator in this case is comparing the references to the two
lists, not their contents. If you wish to compare the contents, you'll need
to write your own code to do so.
> hi,
>
[quoted text clipped - 13 lines]
> TIA
> Irfan
Joanna Carter [TeamB] - 02 Jan 2007 19:34 GMT
| In the simplest form, i have two generic lists and i want to compare if the
| elements in each of them exactly match.
[quoted text clipped - 6 lines]
|
| list1 == list2 returns false
The default implementation fo the equality operator is to use
ReferenceEquals, which simply compares the references to the objects, not
their contents.
You will have to iterate over both lists, comparing elements one by one.
Joanna

Signature
Joanna Carter [TeamB]
Consultant Software Engineer
Mattias Sjögren - 02 Jan 2007 19:52 GMT
>Can someone point me to the right direction.
Compare element by element.
Mattias

Signature
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Irfan - 05 Jan 2007 15:14 GMT
thanks for all the replies,
irfan
> >Can someone point me to the right direction.
>
> Compare element by element.
>
> Mattias