PC Review


Reply
Thread Tools Rate Thread

ArrayList.indexOf(self-defined class)

 
 
paulyip
Guest
Posts: n/a
 
      21st Jan 2005
I've create a private class and an arrayList of it. I found that I can't us
indexOf the check whether they are the same. Is it true that they are in
different location in the memory, that I have use a for loop to compare the
value of them (i.e. add an method CompareVenueID() in class and loop it in
in main())?

private class Venue
{
private int venueID;
private string venueName;

public Venue(int ID, string name)
{
this.venueID = ID;
this.venueName = name;
}
public string getVenueName()
{
return this.venueName;
}

public void main() {
arrayList venueList = new ArrayList();
// assign value to the venuelist
for (int i=0; i < 5; i++) {
tempVenue = new Venue(i, "temp name");
venueList.Add(tempVenue);
}
// check whether there are list have valued (1, "temp name");
searchVenue = new (Venue 1, "temp name");
MessageBox.Show(venueList.IndexOf(searchVenue);
}



 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      21st Jan 2005
paulyip <(E-Mail Removed)> wrote:
> I've create a private class and an arrayList of it. I found that I can't us
> indexOf the check whether they are the same. Is it true that they are in
> different location in the memory, that I have use a for loop to compare the
> value of them (i.e. add an method CompareVenueID() in class and loop it in
> in main())?


Either that or override object.Equals(object) - that's what IndexOf
uses to test for equality.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ArrayList and indexOf tony Microsoft C# .NET 2 23rd Aug 2006 08:19 PM
ArrayList.IndexOf method Qubeczek Microsoft Dot NET Compact Framework 0 17th Jun 2006 01:09 PM
serialization of user-defined class vs collection(arraylist, hasht =?Utf-8?B?UmVkIERldmls?= Microsoft Dot NET 0 11th Oct 2005 09:47 AM
ArrayList.IndexOf() does NOT call my Class Equals() Kurt Tischer Microsoft Dot NET Framework 2 12th Feb 2004 06:00 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting Microsoft ASP .NET 0 29th Dec 2003 07:08 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:42 PM.