Home All Groups Group Topic Archive Search About

List.Contains(searchValue)

Author
15 Mar 2009 4:54 PM
John Crews
I am trying to get teh List.Contains to work but I am having difficulty.

I have a class object:

public class exampleList()
{
    public int prop1 {get; set;}
    public string prop2 {get;set:}
}


Now in a method in the exampleList class I am retrieving data of this class type and trying to check if the prop1 value exists in the list by using the List.Contains method.

private void FetchData()

{

exampleList objBAO = new exampleList ();

List<exampleList > objList = new List<exampleList>();

objList = objBAO.Fetch(); //another routine that goes to the database to get the data and returns it in a List<>

//The below code is not working.  I just want to pass an integer value to see if it is in the list

if (!objList.Contains(this.prop1))

{

    //code to process results

}

}

Author
15 Mar 2009 8:28 PM
Jeff Johnson
"John Crews" <trex3***@hotmail.com> wrote in message
news:uDaWy6YpJHA.6132@TK2MSFTNGP06.phx.gbl...

> I am trying to get teh List.Contains to work but I am having difficulty.

[Canned response]
This is a VB "classic" newsgroup. Questions about VB.NET (including VB
2005/2008,
which have dropped .NET from their name) are off-topic here.

Please ask .NET questions in newsgroups with "dotnet" in their names. The
*.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.*
groups on your news server, connect directly to the Microsoft server:
msnews.microsoft.com.

For questions specific to the VB.NET language, use this group:
microsoft.public.dotnet.languages.vb

Please note that things like controls and data access, which have their own
subgroups in the Classic VB hierarchy, are not language-specific in .NET, so
you should look for groups like these:
microsoft.public.dotnet.framework.windowsforms.controls
microsoft.public.dotnet.framework.adonet
(Note that "vb" is not present in the group name.)
Are all your drivers up to date? click for free checkup

Author
15 Mar 2009 10:28 PM
Bill McCarthy
"Jeff Johnson" <i.get@enough.spam> wrote in message
news:u1gtbyapJHA.3868@TK2MSFTNGP02.phx.gbl...
> "John Crews" <trex3***@hotmail.com> wrote in message
> news:uDaWy6YpJHA.6132@TK2MSFTNGP06.phx.gbl...
>
>> I am trying to get teh List.Contains to work but I am having difficulty.
>
> [Canned response]

That code was probably C#
Author
16 Mar 2009 4:00 AM
Jeff Johnson
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
news:%23fIr83bpJHA.4516@TK2MSFTNGP02.phx.gbl...

>>> I am trying to get teh List.Contains to work but I am having difficulty.
>>
>> [Canned response]
>
> That code was probably C#

HAHAHAHAHA!! I even read through it and didn't notice! Guess that's what you
get when you're sitting around coding in C# and you pop into a VB group!
Author
19 Mar 2009 12:43 AM
Bill McCarthy
Show quote Hide quote
"Jeff Johnson" <i.get@enough.spam> wrote in message
news:%23L1m6TrpJHA.3380@TK2MSFTNGP04.phx.gbl...
> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
> news:%23fIr83bpJHA.4516@TK2MSFTNGP02.phx.gbl...
>
>>>> I am trying to get teh List.Contains to work but I am having
>>>> difficulty.
>>>
>>> [Canned response]
>>
>> That code was probably C#
>
> HAHAHAHAHA!! I even read through it and didn't notice! Guess that's what
> you get when you're sitting around coding in C# and you pop into a VB
> group!


LOl.  I never have that problem reading the code..  but if I've been writing
in it for even half an hour I find it really hard not to add ; everywhere
when I switch back to VB ;)
Author
15 Mar 2009 10:32 PM
Bill McCarthy
Hi John,

Your code looks like it is C#, in which case best to ask in a CSharp
newsgroup such as :

microsoft.public.dotnet.languages.csharp

Most likely the suggestions will be to use a Dictionary<int, exampleList> or
a comparer with the list, but best top have that discussion in the c# forums
as there are many alternatives, few if any oif which apply to early (pre
..NET) versions of VB.



"John Crews" <trex3***@hotmail.com> wrote in message
news:uDaWy6YpJHA.6132@TK2MSFTNGP06.phx.gbl...
I am trying to get teh List.Contains to work but I am having difficulty.

I have a class object:

public class exampleList()
{
    public int prop1 {get; set;}
    public string prop2 {get;set:}
}


Now in a method in the exampleList class I am retrieving data of this class
type and trying to check if the prop1 value exists in the list by using the
List.Contains method.

private void FetchData()

{

exampleList objBAO = new exampleList ();

List<exampleList > objList = new List<exampleList>();

objList = objBAO.Fetch(); //another routine that goes to the database to get
the data and returns it in a List<>

//The below code is not working.  I just want to pass an integer value to
see if it is in the list

if (!objList.Contains(this.prop1))

{

    //code to process results

}

}

Bookmark and Share