Re: List<>.Exists()???
- From: "Marc Gravell" <marc.gravell@xxxxxxxxx>
- Date: Tue, 4 Dec 2007 07:43:58 -0000
What you are looking for is List<T>.Contains(...), i.e.
if(!numList.Contains(newNumber)) {...}
That should fix it; for completeness:
List<T>.Exists(...) checks whether any of the items in the list
satisfies a condition (specified as a predicate); for example, to test
whether any of the numbers are divisible by 3 (using the new C# 3
"lambda" syntax):
if (numList.Exists(i => i % 3 == 0)) {...}
The "predicate" is just a method that accepts the item to be tested
and returns true (match) or false:
static bool SomeMethod(int i) {
return i % 3 == 0;
}
....
if (numList.Exists(SomeMethod)) {...}
Does that make it any clearer?
Marc
.
- Follow-Ups:
- Re: List<>.Exists()???
- From: Ben Voigt [C++ MVP]
- Re: List<>.Exists()???
- References:
- List<>.Exists()???
- From: A
- List<>.Exists()???
- Prev by Date: Re: #Temp tables in SPROCS do not have return values in generated methods
- Next by Date: DataGridView - BindingSource Help Needed
- Previous by thread: List<>.Exists()???
- Next by thread: Re: List<>.Exists()???
- Index(es):
Relevant Pages
|