473,404 Members | 2,114 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,404 software developers and data experts.

List.Exists method

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<intid = new List<int>();
...
populate list
...
id.Exists(10);
id.Exists(12);
....

Someone can help me out?

Thanks
Stijn

Feb 7 '07 #1
2 9074

"Tarscher" <ta******@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
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<intid = new List<int>();
..
populate list
..
id.Exists(10);
id.Exists(12);
use List.Contains or List.IndexOf
...

Someone can help me out?

Thanks
Stijn

Feb 7 '07 #2
Run this:

List<intlist=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

"Tarscher" <ta******@gmail.comwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
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<intid = new List<int>();
..
populate list
..
id.Exists(10);
id.Exists(12);
...

Someone can help me out?

Thanks
Stijn

Feb 7 '07 #3

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

Similar topics

65
by: Steven Watanabe | last post by:
I know that the standard idioms for clearing a list are: (1) mylist = (2) del mylist I guess I'm not in the "slicing frame of mind", as someone put it, but can someone explain what the...
2
by: sianan | last post by:
I am having a problem doing the following in generics. I have two list of a custom item type. I need to iterate through the first list and match each item against another list to see if there is...
5
by: =?Utf-8?B?QnJlbmRlbiBCaXhsZXI=?= | last post by:
Hello. I am reading a value from a table and trying to determine if that value exists in a list of values associated with a dropdownlist. If so, I select the value, otherwise, I don't. I haven't...
2
by: =?Utf-8?B?bWdvbnphbGVzMw==?= | last post by:
I have a List<tobject consisting of objects which in themselves consist of BindingListViews of objects. When I want to search for a object value I normally create a foreach loop and increment a...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
2
by: Jeff | last post by:
..NET 2.0 I'm trying to use List.Contains to determine if an object already exist in the list. This Contains method always return false in my code In my code a method gets a list of names, the...
6
by: A | last post by:
Hi, I don't get this method... Could someone please explain it? I have a number generator where I want to add the numbers to a List<long>. Before I add each number, I want to make sure that the...
12
by: Philip Mueller | last post by:
Hi, I am using multiple stl::list s of different types. Now I want to write a function list<type>::iterator s_erase(list<typel, list<type>::iterator it) that takes an iterator and deletes...
5
by: Mike Kent | last post by:
For Python 2.5 and new-style classes, what special method is called for mylist = seq and for del mylist (given that mylist is a list, and seq is some sequence)? I'm trying to subclass list, and...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...

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.