Re: List<>.Exists()???




"Marc Gravell" <marc.gravell@xxxxxxxxx> wrote in message
news:O3nwLkkNIHA.3940@xxxxxxxxxxxxxxxxxxxxxxx
What you are looking for is List<T>.Contains(...), i.e.



This answer has come up before...

I think it may have something to do with the fact that the help article for
Exists doesn't mention Contains anywhere, never mind as a "Remarks: To find
whether the list contains an element equal to a provided element, use the
Contains method".

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



.



Relevant Pages

  • Re: List<>.Exists()???
    ... That should fix it; for completeness: ... The "predicate" is just a method that accepts the item to be tested ... Marc ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Pthread programming: about the lost condition signals.
    ... If a thread makes the predicate true and it's supposed to be false, ... signals to get the appropriate A or B thread to fix the problem. ... or use broadcasts. ...
    (comp.programming.threads)
  • Re: Return only most recent date records
    ... Can you explain the predicate 'TOP 1*'? ... > PerL ... so I don't know what to fix. ...
    (microsoft.public.access.queries)
  • copy_term/2 in Eclipse
    ... I want to use the copy_term/2 predicate in order to generate the copy of ... the orginial term. ... Does anyone have an idea of how to fix this (or what ... Any hint would be welcome. ...
    (comp.lang.prolog)
  • Re: completeness of predicate calculus
    ... dissertation had been on the completeness of predicate calculus (which ... she called limpid calculus). ... What exactly does it mean for predicate ... - that's a different sort of completeness. ...
    (sci.logic)