List.Exists method

  • Thread starter Thread starter Tarscher
  • Start date Start date
T

Tarscher

Hi all,

I have a list of integers and simply want to check if a number exists
in that list. In the manual I found the List.Exists method but this
apparently only works for constants values via a predicate? Am I wrong
here?

What I want to do
List<int> id = new List<int>();
...
populate list
...
id.Exists(10);
id.Exists(12);
....

Someone can help me out?

Thanks
Stijn
 
Tarscher said:
Hi all,

I have a list of integers and simply want to check if a number exists
in that list. In the manual I found the List.Exists method but this
apparently only works for constants values via a predicate? Am I wrong
here?

What I want to do
List<int> id = new List<int>();
..
populate list
..
id.Exists(10);
id.Exists(12);

use List.Contains or List.IndexOf
 
Run this:

List<int> list=new List<int>();
for (int i=0;i<50;i++) {
list.Add(i);
}
int seekMe=23;
if (list.Contains(seekMe)) {
Console.WriteLine("Yep, there is a {0} in the list", seekMe);
} else {
Console.WriteLine("Nope, there isn't a {0} in the list", seekMe);
}

Hth.
Fabrizio
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top