473,388 Members | 1,377 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,388 software developers and data experts.

Contains Method of Collection

Does anybody know how to determine if a collection contains a specific
member but not by key value as performed by the contains method? I have a
collection of custom structures that I only want to add if it isn't already
there. I could write a test function that would step through the whole
collection and test but I'm hoping there is an easier way. No?

Best regards,

Dale
Nov 24 '05 #1
1 1406
Hi Dale,

Welcome to MSDN newsgroup.
As for .NET collection classes, most of them implement the following
interfaces:

ICollection, IEnumerate, IList ....

And the IEnumeate and ICollection only provide enumerate interface to loop
through the collection ,so I'm afraid only those collection implement IList
can we use Contains or IndexOf method to lookup certain object... And for
most other collection ,we have to manually loop through the items and check
them...
In addition, if you're designing a custom Collection class, you can
consider add a custom method which will set a flag on the collectoni's
member field to mark whether it contains a specific value or object....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



--------------------
| From: "Dale Levesque" <dm*****@newsgroups.nospam>
| Subject: Contains Method of Collection
| Date: Thu, 24 Nov 2005 15:34:07 -0800
| Lines: 11
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1506
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1506
| Message-ID: <Oi**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 70.69.242.240
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.languages.vb:305736
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| Does anybody know how to determine if a collection contains a specific
| member but not by key value as performed by the contains method? I have a
| collection of custom structures that I only want to add if it isn't
already
| there. I could write a test function that would step through the whole
| collection and test but I'm hoping there is an easier way. No?
|
| Best regards,
|
| Dale
|
|
|

Nov 25 '05 #2

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

Similar topics

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...
5
by: songie D | last post by:
I have a collection class that contains objects of the type of another class call it Class1, that I have created. The constructor for Class1 takes two integers These go on to be fields of the...
3
by: andrew.miadowicz | last post by:
It's funny that I've only now run into this question, after a few years of using C#, but I find it intriguiging all the same. All the more so, that the generic version of ICollection in .Net...
4
by: Robert W. | last post by:
I've built a complex collection object from "System.Collections.CollectionBase". With regard to it, I have a question about the "Contains" method. At first I thought that "Contains" would...
5
by: matt tagliaferri | last post by:
I'm implementing a typed collection class that can't include duplicates. The Add method of the collection class is as follows: Public Function Add(ByVal o As TeamListEntry) As Integer If...
3
by: JB | last post by:
I've created a generic of type List<T> where T is a custom class. I need to use the List<T>.Contains method. I know I need to implement the IEqualityComparer but I can't seem to get the Contains...
3
by: Kevin Burton | last post by:
I have a Collection object and I would like to know if a particular key is in the collection so naturally I try something like: myObject.Contains(key) But when I compile the project I get: ...
2
by: Jon | last post by:
Hello all. I have a collection class that holds a number of clauses. One particular type of clause has a member variable called type - this is an enum. How do I check this collection class to...
8
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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...

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.