473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

ArrayList.Contains?

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

Jul 21 '05 #1
1 1645
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,
--
Angel J. Hernández M.
MCP - MCAD - MCSD - MCDBA
http://groups.msn.com/desarrolladoresmiranda
http://ajhsis.net

"thechaosengine" <na> escribió en el mensaje
news:81********************@news.microsoft.com...
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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: C Downey | last post by:
Hello: I have an arraylist storing some very basic objects. The object is very basic, it has 2 properties : ID, and COUNT Before I add an object to the arraylist, I want to check if an...
4
by: tma | last post by:
I'm trying to save code to a session object like the following: dim oAppList as arraylist dim oApp as someclass Code to manipulate oApp... .... .... oApplist.Add(oApp)...
9
by: Leon | last post by:
I have a webform in which when the user press generate button the form generate six unique ramdon numbers, the user can also type these six numbers in manually in any order. however, the user can...
20
by: Dennis | last post by:
I use the following code for a strongly typed arraylist and it works great. However, I was wondering if this is the proper way to do it. I realize that if I want to implement sorting of the...
1
by: thechaosengine | last post by:
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...
12
by: Robert Hooker | last post by:
We are moving to .NET2.0 - and have noticed that .Contains() seems to be around 20% slower under NET2, compared to NET1.1. This code shows the issue: static void Main(string args) {...
14
by: Kym | last post by:
Hey, I have an arraylist which I have added a number of objects to (all the same type of object), I need to be able to check if the array already contain the object before adding it, I have tried...
3
by: Christopher H | last post by:
I've been reading about how C# passes ArrayLists as reference and Structs as value, but I still can't get my program to work like I want it to. Simple example: ...
7
by: Kamran Shafi | last post by:
Hi, I am creating an arraylist (say masterArrayList) of hashtables, where each hashtable (say table) is of the format key=string, value = arraylist of strings (say existing_strings). In a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.