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
|
|
|