ArrayList.indexOf(self-defined class)

P

paulyip

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);
}
 
J

Jon Skeet [C# MVP]

paulyip said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top