>I was browsing the vs2005 beta and was wondering if someone could show
>me an example of the Array.Find<> usage, specifically how to write
>"Predicates".
You can write them as regular or anonymous methods, as long as they
match the Predicate<T> signature.
>Say I have an array of DateTime objects, and I wanted to find the date
>Apr. 23, 2005 8:30am from the array - how does one write the
>"predicate"
Something like
DateTime dt = Array.Find<DateTime>( yourDateTimeArray,
delegate(DateTime obj) {
return obj == new DateTime(2005, 4, 23, 8, 30, 0);
}
);
This however doesn't make sense. Since you know the value of the item
you're searching for, you could just as well assign it to dt directly.
You would typically use Find for searching with a criteria other than
equality.
>does the "search" terminate after it finds the value,
>or are all values always scanned?
Yes, it returns the first match found.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
Please reply only to the newsgroup.