example please of how to use Array.Exists method

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Dim Animals as String() = {"cat", "dog", "mouse", "rat"}

Can the Exists or Find method be used to determine if the Animals array
contains "mouse" ?

If Animals.Exists(....

or

Animals.Find(...

I get a compiler error: Type argument inferred from the argument passed
to parameter 'match'conflicts with the type argument inferred from the
argument passed to parameter 'array'.

Thanks
Tim
 
Tim said:
Dim Animals as String() = {"cat", "dog", "mouse", "rat"}

Can the Exists or Find method be used to determine if the Animals array
contains "mouse" ?

If Animals.Exists(....

or

Animals.Find(...

The methods can be used for that, but not that way. The Exists and Find
method are static, so it would be:

found = Array.Exists(Animals, ... )

and

animal = Array.Find(Animals, ... )
I get a compiler error: Type argument inferred from the argument passed
to parameter 'match'conflicts with the type argument inferred from the
argument passed to parameter 'array'.

That means that the type of the array doesn't match the argument in your
predicate. If you show a bit of the code, someone might be able to help
you with it.
 
Back
Top