PC Review


Reply
Thread Tools Rate Thread

Anonymous methods

 
 
puzzlecracker
Guest
Posts: n/a
 
      16th Oct 2008
Can you make an Anonymous methods receive and return values?
Otherwise, they appear useful for void methods?

Thanks
 
Reply With Quote
 
 
 
 
Cowboy \(Gregory A. Beamer\)
Guest
Posts: n/a
 
      16th Oct 2008
http://davidhayden.com/blog/dave/arc...5/28/2974.aspx

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************
"puzzlecracker" <(E-Mail Removed)> wrote in message
news:89c022bc-9518-4e78-8cdf-(E-Mail Removed)...
> Can you make an Anonymous methods receive and return values?
> Otherwise, they appear useful for void methods?
>
> Thanks


 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      16th Oct 2008
On Oct 16, 10:33 am, puzzlecracker <ironsel2...@gmail.com> wrote:
> Can you make an Anonymous methods receive and return values?
> Otherwise, they appear useful for void methods?
>
> Thanks


of course an anonymous method can return a value:
delegate int DoIt();
DoIt d = delegate{ return 2;};
DoIt d1 = () => 12; //now using a lambda expression
int qpp;
qpp = d();
 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      16th Oct 2008
Yes:

Predicate<int> isEven = delegate(int i)
{ return i % 2 == 0; }; // C# 2.0
Predicate<int> isEven = i => i % 2 == 0; // C# 3.0

Console.WriteLine(isEven(4));
Console.WriteLine(isEven(5));

Marc
 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      16th Oct 2008
On Oct 16, 10:48*am, Marc Gravell <marc.grav...@gmail.com> wrote:
> Yes:
>
> * * * * *Predicate<int> isEven = delegate(int i)
> * * * * * * { return i % 2 == 0; }; // C# 2.0
> * * * * *Predicate<int> isEven = i => i % 2 == 0; // C#3.0
>
> * * * * *Console.WriteLine(isEven(4));
> * * * * *Console.WriteLine(isEven(5));
>
> Marc



What's Predicate<int>, not familiar with Predicate class.

Thanks
 
Reply With Quote
 
Peter Morris
Guest
Posts: n/a
 
      16th Oct 2008
I can't help but wonder how many puzzles you actually crack :-)



--
Pete
====
http://mrpmorris.blogspot.com
http://www.capableobjects.com
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      16th Oct 2008
On Oct 16, 11:08 am, "Peter Morris" <mrpmorri...@SPAMgmail.com> wrote:
> I can't help but wonder how many puzzles you actually crack :-)
>
> --
> Pete
> ====http://mrpmorris.blogspot.comhttp://www.capableobjects.com


:-)
 
Reply With Quote
 
Ignacio Machin ( .NET/ C# MVP )
Guest
Posts: n/a
 
      16th Oct 2008
On Oct 16, 10:58 am, puzzlecracker <ironsel2...@gmail.com> wrote:
> On Oct 16, 10:48 am, Marc Gravell <marc.grav...@gmail.com> wrote:
>
> > Yes:

>
> > Predicate<int> isEven = delegate(int i)
> > { return i % 2 == 0; }; // C# 2.0
> > Predicate<int> isEven = i => i % 2 == 0; // C# 3.0

>
> > Console.WriteLine(isEven(4));
> > Console.WriteLine(isEven(5));

>
> > Marc

>
> What's Predicate<int>, not familiar with Predicate class.
>
> Thanks


It's a predefined delegate. It is defined as :
public delegate bool Predicate<T>

very used in List operations like Find, FindFirst, etc
 
Reply With Quote
 
Peter Morris
Guest
Posts: n/a
 
      17th Oct 2008
> What's Predicate<int>, not familiar with Predicate class.

Simple questions like this can easily by answered by typing the following
into google

msdn predicate

Additionally, if you are not already familiar with it, you might be
interested in Reflector..

http://www.red-gate.com/products/reflector/index.htm


Regards


--
Pete
====
http://mrpmorris.blogspot.com
http://www.capableobjects.com

 
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
Re: Help with anonymous methods Göran Andersson Microsoft C# .NET 1 2nd Sep 2008 04:00 AM
anonymous methods only available in C#? PJ6 Microsoft VB .NET 22 17th Aug 2006 02:28 PM
using anonymous methods Alexandre Microsoft ASP .NET 7 8th Feb 2006 03:08 AM
Anonymous Methods John Smith Microsoft C# .NET 9 26th Jan 2006 03:42 PM
anonymous methods in c++/CLI bonk Microsoft VC .NET 2 14th Oct 2005 03:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 AM.