Re: Search Array
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 19 Jan 2009 14:41:45 -0800
On Mon, 19 Jan 2009 14:22:28 -0800, Jonathan Wood <jwood@xxxxxxxxxxxxxxxx> wrote:
I've created a simple array of unsorted strings.
Is there a SIMPLE way to see if the array contains a string while ignoring case, without writing my own loop?
I don't mind writing my own loop but if there's already something to do this, I'd like to find it. I've found all sorts of complex stuff but nothing to perform this rather trivial task.
It is a rather trivial task. Any particular reason you want to avoid the extra few lines required for an explicit loop?
You can use Array.Find<T>() or Enumerable.Contains<TSource>(). Either of those will allow you to provide a predicate that does the exact comparison you want (Array.Find<T>() is probably easier, since it allows you to provide the predicate directly, rather than wrapping it in an interface implementation).
But loops aren't exactly evil or anything. It wouldn't be the end of the world if you had to write one yourself. :)
Pete
.
- Follow-Ups:
- Re: Search Array
- From: Jonathan Wood
- Re: Search Array
- References:
- Search Array
- From: Jonathan Wood
- Search Array
- Prev by Date: Re: Delegates VS interfaces - some confusion
- Next by Date: Re: Search Array
- Previous by thread: Search Array
- Next by thread: Re: Search Array
- Index(es):
Relevant Pages
|