473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1647
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.