PC Review


Reply
Thread Tools Rate Thread

Array.Find<> example

 
 
=?Utf-8?B?RWxpYW5hUw==?=
Guest
Posts: n/a
 
      25th Apr 2005
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".

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", and, does the "search" terminate after it finds the value,
or are all values always scanned?


Is there any sources available yet that discuss this area of C#
generics?


TIA

 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      25th Apr 2005

>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.
 
Reply With Quote
 
Austin Ehlers
Guest
Posts: n/a
 
      26th Apr 2005
On Mon, 25 Apr 2005 08:42:39 -0700, "ElianaS"
<(E-Mail Removed)> wrote:

>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".


<snip>

>Is there any sources available yet that discuss this area of C#
>generics?

Check out Don Box's blog (
http://pluralsight.com/blogs/dbox/default.aspx ). His latest posts
have coverage on generics and anonymous methods (including Array
coverage).

Austin
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Last entry for Col in Multi column array using cell from another array. bob Microsoft Excel Worksheet Functions 1 15th Nov 2010 09:18 PM
Find specific value in array of array formula DzednConfsd Microsoft Excel Worksheet Functions 2 13th Jan 2009 06:19 AM
Looped Find and Array Doesn't Find sbitaxi@gmail.com Microsoft Excel Programming 2 22nd Jul 2008 05:43 PM
Find Existing Value in Array of Array =?Utf-8?B?Um9z?= Microsoft VB .NET 2 12th Jul 2006 08:38 PM
find each of the items in an array and save result in another array lif Microsoft Excel Programming 2 28th Jun 2006 01:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:33 PM.