locked
"( ) =>" ... What is this called? RRS feed

  • Question

  • Hey everyone, I apologize since this isn't 100% Silverlight related, but I came across this while setting up our test framework.

    What exactly does "( ) =>" do, and does it have a name?  For example, I have a function that requires a specific delegate function, and I can do something like this:  DeltaAsyncronous.WaitFor(() => PaletteHasLoaded("default"), 5000);

    This appears to cast the statement on the right to be a delegate?  Searching on google has got me nowhere, so I turn to you all for help!  It's driving me crazy - I need to explain how to use my class functionality - but *I* don't even know exactly how the magic works!!!

     

    Thanks in advance. 

    Tuesday, March 3, 2009 5:32 PM

Answers

All replies

  • Tuesday, March 3, 2009 5:58 PM
  • I believe it's a lambda expression with an empty parameter list.

    More info can be found here: http://msdn.microsoft.com/en-us/library/bb397687.aspx

     

    Tuesday, March 3, 2009 5:59 PM
  • Lambda Expressions!!!

    http://msdn.microsoft.com/en-us/library/bb397687.aspx

    LOL - resharper answered my question by "suggesting" it for me.

    Tuesday, March 3, 2009 6:00 PM
  • Woah... it looks like we were writing our posts at the same time [2:58, 2:59 and 3:00]

    Thank you everyone :) 

     

    Tuesday, March 3, 2009 6:03 PM
  • Although it's called a Lmbda Expression I prefer the use of the name Anonymous Method. Because it's actually an inline method that is passed as an argument, think of it as a method pointer, which can be executed.
    Wednesday, March 4, 2009 1:35 AM
  • Although it's called a Lmbda Expression I prefer the use of the name Anonymous Method. Because it's actually an inline method that is passed as an argument, think of it as a method pointer, which can be executed.
     

    A lambda expression is different from a anonymous method in a way that the lambda expression has the reference to the context from where it is created.

    Wednesday, March 4, 2009 2:11 AM
  • On the toolkit at least, we call the ( ) => lambda an Action since you can define a parameter to a function that takes an Action. So, in the unit test framework, the EnqueueCallback method takes an Action.

    Thursday, March 12, 2009 1:11 PM