Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / January 2007

Tip: Looking for answers? Try searching our database.

comparing two generic Lists

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Irfan - 02 Jan 2007 18:15 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.