0

I'm wondering if there is a difference between using a Lambda expression and the delegate anonymous keyword type. Is one preferred over the other? From what I've seen both seem to be interchangeable.

public delegate void SomeDel(string input);

public class myClass
{

   private ObjWithDel myObj;

   public myClass()
   {
    // Lambda Case
     myObj.DoDel += (val)=>{textbox1.Text = val;}

    // delegate keyword case
     myObj.DoDel += delegate(string val){textbox1.Text = val;}

   }
}
Felix Castor
  • 1,598
  • 1
  • 18
  • 39

1 Answers1

-1

The two are different: a lambda is an "anonymous" method, it doesn't have a permanent name, whereas a Delegate is actually a reference to a method or lambda. Most of the time, lambdas will be faster than delegates, but there's cases where you can only use delegates or lambdas, not the two.

zdimension
  • 977
  • 1
  • 12
  • 33
  • 2
    OP is not asking about the difference between a lambda and a delegate, but rather about the difference between the two syntaxes to create an anonymus method and obtain a delegate holding it. As it happens, there is no difference at runtime. Your statement that a lambda is faster than a delegate makes no sense. – Kris Vandermotten Dec 03 '15 at 19:48