ArrayList.Contains?

  • Thread starter Thread starter thechaosengine
  • Start date Start date
T

thechaosengine

Hi all,

Can anyone tell me how ArrayList.Contains works.

The docs say that it tells you if an *object* is contained in the list. Now,
by object do the docs mean the exact instance that you pass in, or some other
way of working?

I have a situation whereby i have a custom collection extended from an ArrayList,
and I would like to be able to find out if a collection contains an instance
of a user that has a particular userID.

Can anyone advise on what i should use to do that?

Thanks all

tce
 
Hi there... The way it works is through comparing (by using the Equals
method) the object passed in against the entire collection. In your
situation the two objects must contain the same information so the Contains
method can return true.

Sample
*****

System.Collections.ArrayList z = new ArrayList();

for(int p = 0; p < 100; p++)
z.Add(p);

System.Diagnostics.Trace.WriteLine("Does z contain 50?: "+
z.Contains(50).ToString());

Regards,
 

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

Back
Top