<p>I get asked this question a lot and I thought I'd solicit some input on how to best describe the difference.</p>

[{'answer_id': 73249, 'author': 'Joel Coehoorn', 'author_id': 3043, 'author_profile': 'https://Stackoverflow.com/users/3043', 'pm_score': -1, 'selected': False, 'text': '<p>Well, the really oversimplified version is that a lambda is just shorthand for an anonymous function.  A delegate can do a lot more than just anonymous functions: things like events, asynchronous calls, and multiple method chains.</p>\n'}, {'answer_id': 73255, 'author': 'chessguy', 'author_id': 1908025, 'author_profile': 'https://Stackoverflow.com/users/1908025', 'pm_score': 2, 'selected': False, 'text': "<p>I don't have a ton of experience with this, but the way I would describe it is that a delegate is a wrapper around any function, whereas a lambda expression is itself an anonymous function.</p>\n"}, {'answer_id': 73259, 'author': 'Dan Shield', 'author_id': 4633, 'author_profile': 'https://Stackoverflow.com/users/4633', 'pm_score': 4, 'selected': False, 'text': "<p>Delegates are equivalent to function pointers/method pointers/callbacks (take your pick), and lambdas are pretty much simplified anonymous functions.  At least that's what I tell people.</p>\n"}, {'answer_id': 73271, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 2, 'selected': False, 'text': '<p>lambdas are simply syntactic sugar on a delegate. The compiler ends up converting lambdas into delegates.</p>\n\n<p>These are the same, I believe:</p>\n\n<pre><code>Delegate delegate = x =&gt; "hi!";\nDelegate delegate = delegate(object x) { return "hi";};\n</code></pre>\n'}, {'answer_id': 73318, 'author': 'Steve Cooper', 'author_id': 6722, 'author_profile': 'https://Stackoverflow.com/users/6722', 'pm_score': 2, 'selected': False, 'text': '<p>A delegate is a function signature; something like </p>\n\n<pre><code>delegate string MyDelegate(int param1);\n</code></pre>\n\n<p>The delegate does not implement a body. </p>\n\n<p>The lambda is a function call that matches the signature of the delegate. For the above delegate, you might use any of;</p>\n\n<pre><code>(int i) =&gt; i.ToString();\n(int i) =&gt; "ignored i";\n(int i) =&gt; "Step " + i.ToString() + " of 10";\n</code></pre>\n\n<p>The <code>Delegate</code> type is badly named, though; creating an object of type <code>Delegate</code> actually creates a variable which can hold functions -- be they lambdas, static methods, or class methods.</p>\n'}, {'answer_id': 73367, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 2, 'selected': False, 'text': '<p>A delegate is always just basically a function pointer.  A lambda can turn into a delegate, but it can also turn into a LINQ expression tree.  For instance,</p>\n\n<pre><code>Func&lt;int, int&gt; f = x =&gt; x + 1;\nExpression&lt;Func&lt;int, int&gt;&gt; exprTree = x =&gt; x + 1;\n</code></pre>\n\n<p>The first line produces a delegate, while the second produces an expression tree.</p>\n'}, {'answer_id': 73384, 'author': 'Steve g', 'author_id': 12092, 'author_profile': 'https://Stackoverflow.com/users/12092', 'pm_score': 1, 'selected': False, 'text': '<p>Delegates are really just structural typing for functions.  You could do the same thing with nominal typing and implementing an anonymous class that implements an interface or abstract class, but that ends up being a lot of code when only one function is needed.</p>\n\n<p>Lambda comes from the idea of lambda calculus of Alonzo Church in the 1930s.  It is an anonymous way of creating functions. They become especially useful for composing functions</p>\n\n<p>So while some might say lambda is syntactic sugar for delegates, I would says delegates are a bridge for easing people into lambdas in c#.</p>\n'}, {'answer_id': 73408, 'author': 'Michael Meadows', 'author_id': 7643, 'author_profile': 'https://Stackoverflow.com/users/7643', 'pm_score': 0, 'selected': False, 'text': '<p>Lambdas are simplified versions of delegates.  They have some of the the properties of a <a href="http://en.wikipedia.org/wiki/Closure_(computer_science)" rel="nofollow noreferrer">closure</a> like anonymous delegates, but also allow you to use implied typing.  A lambda like this:</p>\n\n<pre><code>something.Sort((x, y) =&gt; return x.CompareTo(y));\n</code></pre>\n\n<p>is a lot more concise than what you can do with a delegate:</p>\n\n<pre><code>something.Sort(sortMethod);\n...\n\nprivate int sortMethod(SomeType one, SomeType two)\n{\n    one.CompareTo(two)\n}\n</code></pre>\n'}, {'answer_id': 73448, 'author': 'Karg', 'author_id': 12685, 'author_profile': 'https://Stackoverflow.com/users/12685', 'pm_score': 5, 'selected': False, 'text': '<p>One difference is that an anonymous delegate can omit parameters while a lambda must match the exact signature. Given:</p>\n\n<pre><code>public delegate string TestDelegate(int i);\n\npublic void Test(TestDelegate d)\n{}\n</code></pre>\n\n<p>you can call it in the following four ways (note that the second line has an anonymous delegate that does not have any parameters):</p>\n\n<pre><code>Test(delegate(int i) { return String.Empty; });\nTest(delegate { return String.Empty; });\nTest(i =&gt; String.Empty);\nTest(D);\n\nprivate string D(int i)\n{\n    return String.Empty;\n}\n</code></pre>\n\n<p>You cannot pass in a lambda expression that has no parameters or a method that has no parameters. These are not allowed:</p>\n\n<pre><code>Test(() =&gt; String.Empty); //Not allowed, lambda must match signature\nTest(D2); //Not allowed, method must match signature\n\nprivate string D2()\n{\n    return String.Empty;\n}\n</code></pre>\n'}, {'answer_id': 73819, 'author': 'Chris Ammerman', 'author_id': 2729, 'author_profile': 'https://Stackoverflow.com/users/2729', 'pm_score': 8, 'selected': True, 'text': '<p>They are actually two very different things. "Delegate" is actually the name for a variable that holds a reference to a method or a lambda, and a lambda is a method without a permanent name.</p>\n\n<p>Lambdas are very much like other methods, except for a couple subtle differences.</p>\n\n<ol>\n<li>A normal method is defined in a <a href="http://en.wikipedia.org/wiki/Statement_(programming)" rel="noreferrer">"statement"</a> and tied to a permanent name, whereas a lambda is defined "on the fly" in an <a href="http://en.wikipedia.org/wiki/Expression_(programming)" rel="noreferrer">"expression"</a> and has no permanent name.</li>\n<li>Some lambdas can be used with .NET expression trees, whereas methods cannot.</li>\n</ol>\n\n<p>A delegate is defined like this:</p>\n\n<pre><code>delegate Int32 BinaryIntOp(Int32 x, Int32 y);\n</code></pre>\n\n<p>A variable of type BinaryIntOp can have either a method or a labmda assigned to it, as long as the signature is the same: two Int32 arguments, and an Int32 return.</p>\n\n<p>A lambda might be defined like this:</p>\n\n<pre><code>BinaryIntOp sumOfSquares = (a, b) =&gt; a*a + b*b;\n</code></pre>\n\n<p>Another thing to note is that although the generic Func and Action types are often considered "lambda types", they are just like any other delegates.  The nice thing about them is that they essentially define a name for any type of delegate you might need (up to 4 parameters, though you can certainly add more of your own).  So if you are using a wide variety of delegate types, but none more than once, you can avoid cluttering your code with delegate declarations by using Func and Action.</p>\n\n<p>Here is an illustration of how Func and Action are "not just for lambdas":</p>\n\n<pre><code>Int32 DiffOfSquares(Int32 x, Int32 y)\n{\n  return x*x - y*y;\n}\n\nFunc&lt;Int32, Int32, Int32&gt; funcPtr = DiffOfSquares;\n</code></pre>\n\n<p>Another useful thing to know is that delegate types (not methods themselves) with the same signature but different names will not be implicitly casted to each other.  This includes the Func and Action delegates.  However if the signature is identical, you can explicitly cast between them.</p>\n\n<p>Going the extra mile....  In C# functions are flexible, with the use of lambdas and delegates.  But C# does not have "first-class functions".  You can use a function\'s name assigned to a delegate variable to essentially create an object representing that function.  But it\'s really a compiler trick.  If you start a statement by writing the function name followed by a dot (i.e. try to do member access on the function itself) you\'ll find there are no members there to reference.  Not even the ones from Object.  This prevents the programmer from doing useful (and potentially dangerous of course) things such as adding extension methods that can be called on any function.  The best you can do is extend the Delegate class itself, which is surely also useful, but not quite as much.</p>\n\n<p>Update: Also see <a href="https://stackoverflow.com/questions/73227/what-is-the-difference-between-lambdas-and-delegates-in-the-net-framework#73448">Karg\'s answer</a> illustrating the difference between anonymous delegates vs. methods &amp; lambdas.</p>\n\n<p>Update 2: <a href="https://stackoverflow.com/questions/73227/what-is-the-difference-between-lambdas-and-delegates-in-the-net-framework#74414">James Hart</a> makes an important, though very technical, note that lambdas and delegates are not .NET entities (i.e. the CLR has no concept of a delegate or lambda), but rather they are framework and language constructs.</p>\n'}, {'answer_id': 74079, 'author': 'Echostorm', 'author_id': 12862, 'author_profile': 'https://Stackoverflow.com/users/12862', 'pm_score': 0, 'selected': False, 'text': "<p>Heres an example I put up awhile on my lame blog.  Say you wanted to update a label from a worker thread.  I've got 4 examples of how to update that label from 1 to 50 using delegates, anon delegates and 2 types of lambdas.</p>\n\n<pre><code> private void button2_Click(object sender, EventArgs e) \n     { \n         BackgroundWorker worker = new BackgroundWorker(); \n         worker.DoWork += new DoWorkEventHandler(worker_DoWork); \n         worker.RunWorkerAsync(); \n     } \n\n     private delegate void UpdateProgDelegate(int count); \n     private void UpdateText(int count) \n     { \n         if (this.lblTest.InvokeRequired) \n         { \n             UpdateProgDelegate updateCallBack = new UpdateProgDelegate(UpdateText); \n             this.Invoke(updateCallBack, new object[] { count }); \n         } \n         else \n         { \n             lblTest.Text = count.ToString(); \n         } \n     } \n\n     void worker_DoWork(object sender, DoWorkEventArgs e) \n     {   \n         /* Old Skool delegate usage.  See above for delegate and method definitions */ \n         for (int i = 0; i &lt; 50; i++) \n         { \n             UpdateText(i); \n             Thread.Sleep(50); \n         } \n\n         // Anonymous Method \n         for (int i = 0; i &lt; 50; i++) \n         { \n             lblTest.Invoke((MethodInvoker)(delegate() \n             { \n                 lblTest.Text = i.ToString(); \n             })); \n             Thread.Sleep(50); \n         } \n\n         /* Lambda using the new Func delegate. This lets us take in an int and \n          * return a string.  The last parameter is the return type. so \n          * So Func&lt;int, string, double&gt; would take in an int and a string \n          * and return a double.  count is our int parameter.*/ \n         Func&lt;int, string&gt; UpdateProgress = (count) =&gt; lblTest.Text = count.ToString(); \n         for (int i = 0; i &lt; 50; i++) \n         { \n             lblTest.Invoke(UpdateProgress, i); \n             Thread.Sleep(50); \n         } \n\n         /* Finally we have a totally inline Lambda using the Action delegate \n          * Action is more or less the same as Func but it returns void. We could \n          * use it with parameters if we wanted to like this: \n          * Action&lt;string&gt; UpdateProgress = (count) =&gt; lblT…*/ \n         for (int i = 0; i &lt; 50; i++) \n         { \n             lblTest.Invoke((Action)(() =&gt; lblTest.Text = i.ToString())); \n             Thread.Sleep(50); \n         } \n     }\n</code></pre>\n"}, {'answer_id': 74283, 'author': 'Peter Ritchie', 'author_id': 5620, 'author_profile': 'https://Stackoverflow.com/users/5620', 'pm_score': 2, 'selected': False, 'text': '<p>A delegate is a reference to a method with a particular parameter list and return type.  It may or may not include an object.</p>\n\n<p>A lambda-expression is a form of anonymous function.</p>\n'}, {'answer_id': 74303, 'author': 'justin.m.chase', 'author_id': 12958, 'author_profile': 'https://Stackoverflow.com/users/12958', 'pm_score': 2, 'selected': False, 'text': '<p>A delegate is a Queue of function pointers, invoking a delegate may invoke multiple methods. A lambda is essentially an anonymous method declaration which may be interpreted by the compiler differently, depending on what context it is used as.</p>\n\n<p>You can get a delegate that points to the lambda expression as a method by casting it into a delegate, or if passing it in as a parameter to a method that expects a specific delegate type the compiler will cast it for you. Using it inside of a LINQ statement, the lambda will be translated by the compiler into an expression tree instead of simply a delegate.</p>\n\n<p>The difference really is that a lambda is a terse way to define a method inside of another expression, while a delegate is an actual object type.</p>\n'}, {'answer_id': 74414, 'author': 'James Hart', 'author_id': 5755, 'author_profile': 'https://Stackoverflow.com/users/5755', 'pm_score': 5, 'selected': False, 'text': "<p>The question is a little ambiguous, which explains the wide disparity in answers you're getting.</p>\n\n<p>You actually asked what the difference is between lambdas and delegates in the .NET framework; that might be one of a number of things. Are you asking:</p>\n\n<ul>\n<li><p>What is the difference between lambda expressions and anonymous delegates in the C# (or VB.NET) language?</p></li>\n<li><p>What is the difference between System.Linq.Expressions.LambdaExpression objects and System.Delegate objects in .NET 3.5?</p></li>\n<li><p>Or something somewhere between or around those extremes?</p></li>\n</ul>\n\n<p>Some people seem to be trying to give you the answer to the question 'what is the difference between C# Lambda expressions and .NET System.Delegate?', which doesn't make a whole lot of sense.</p>\n\n<p>The .NET framework does not in itself understand the concepts of anonymous delegates, lambda expressions, or closures - those are all things defined by language specifications. Think about how the C# compiler translates the definition of an anonymous method into a method on a generated class with member variables to hold closure state; to .NET, there's nothing anonymous about the delegate; it's just anonymous to the C# programmer writing it. That's equally true of a lambda expression assigned to a delegate type.</p>\n\n<p>What .NET <em>DOES</em> understand is the idea of a delegate - a type that describes a method signature, instances of which represent either bound calls to specific methods on specific objects, or unbound calls to a particular method on a particular type that can be invoked against any object of that type, where said method adheres to the said signature. Such types all inherit from System.Delegate.</p>\n\n<p>.NET 3.5 also introduces the System.Linq.Expressions namespace, which contains classes for describing code expressions - and which can also therefore represent bound or unbound calls to methods on particular types or objects. LambdaExpression instances can then be compiled into actual delegates (whereby a dynamic method based on the structure of the expression is codegenned, and a delegate pointer to it is returned).</p>\n\n<p>In C# you can produce instances of System.Expressions.Expression types by assigning a lambda expression to a variable of said type, which will produce the appropriate code to construct the expression at runtime.</p>\n\n<p>Of course, if you <em>were</em> asking what the difference is between lambda expressions and anonymous methods in C#, after all, then all this is pretty much irelevant, and in that case the primary difference is brevity, which leans towards anonymous delegates when you don't care about parameters and don't plan on returning a value, and towards lambdas when you want type inferenced parameters and return types.</p>\n\n<p>And lambda expressions support expression generation.</p>\n"}, {'answer_id': 6460111, 'author': 'Philip Beber', 'author_id': 813016, 'author_profile': 'https://Stackoverflow.com/users/813016', 'pm_score': 2, 'selected': False, 'text': '<p>It is pretty clear the question was meant to be "what\'s the difference between lambdas and <strong>anonymous</strong> delegates?" Out of all the answers here only one person got it right - the main difference is that lambdas can be used to create expression trees as well as delegates.</p>\n\n<p>You can read more on MSDN: <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb397687.aspx</a></p>\n'}, {'answer_id': 27059973, 'author': 'Olorin', 'author_id': 1581875, 'author_profile': 'https://Stackoverflow.com/users/1581875', 'pm_score': 0, 'selected': False, 'text': '<p><em>I assume that your question concerns c# and not .NET, because of the ambiguity of your question, as .NET does not get alone - that is, without c# - comprehension of delegates and lambda expressions.</em></p>\n\n<p>A (<em>normal</em>, in opposition to so called <em>generic</em> delegates, <em>cf</em> later) delegate should be seen as a kind of c++ <code>typedef</code> of a function pointer type, for instance in c++ :</p>\n\n<pre><code>R (*thefunctionpointer) ( T ) ;\n</code></pre>\n\n<p>typedef\'s the type <code>thefunctionpointer</code> which is the type of pointers to a function taking an object of type <code>T</code> and returning an object of type <code>R</code>. You would use it like this :</p>\n\n<pre><code>thefunctionpointer = &amp;thefunction ;\nR r = (*thefunctionpointer) ( t ) ; // where t is of type T\n</code></pre>\n\n<p>where <code>thefunction</code> would be a function taking a <code>T</code> and returning an <code>R</code>.</p>\n\n<p>In c# you would go for</p>\n\n<pre><code>delegate R thedelegate( T t ) ; // and yes, here the identifier t is needed\n</code></pre>\n\n<p>and you would use it like this :</p>\n\n<pre><code>thedelegate thedel = thefunction ;\nR r = thedel ( t ) ; // where t is of type T\n</code></pre>\n\n<p>where <code>thefunction</code> would be a function taking a <code>T</code> and returning an <code>R</code>. This is for delegates, so called normal delegates.</p>\n\n<p>Now, you also have generic delegates in c#, which are delegates that are generic, <em>i.e.</em> that are "templated" so to speak, using thereby a c++ expression. They are defined like this :</p>\n\n<pre><code>public delegate TResult Func&lt;in T, out TResult&gt;(T arg);\n</code></pre>\n\n<p>And you can used them like this :</p>\n\n<pre><code>Func&lt;double, double&gt; thefunctor = thefunction2; // call it a functor because it is\n                                                // really as a functor that you should\n                                                // "see" it\ndouble y = thefunctor(2.0);\n</code></pre>\n\n<p>where <code>thefunction2</code> is a function taking as argument and returning a <code>double</code>.</p>\n\n<p>Now imagine that instead of <code>thefunction2</code> I would like to use a "function" that is nowhere defined for now, by a statement, and that I will never use later. Then c# allows us to use the <em>expression</em> of this function. By expression I mean the "mathematical" (or functional, to stick to programs) expression of it, for instance : to a <code>double x</code> I will <em>associate</em> the <code>double</code> <code>x*x</code>. In maths you write this using <a href="https://math.stackexchange.com/questions/651205/regarding-the-notation-f-a-mapsto-b">the "\\mapsto" latex symbol</a>. In c# the functional notation has been borrowed : <code>=&gt;</code>. For instance :</p>\n\n<pre><code>Func&lt;double, double&gt; thefunctor = ( (double x) =&gt; x * x ); // outer brackets are not\n                                                           // mandatory\n</code></pre>\n\n<p><code>(double x) =&gt; x * x</code> is an <a href="http://en.wikipedia.org/wiki/Expression_(computer_science)" rel="nofollow noreferrer"><em>expression</em></a>. It is not a type, whereas delegates (generic or not) are.</p>\n\n<p>Morality ? At end, what is a delegate (resp. generic delegate), if not a function pointer type (resp. wrapped+smart+generic function pointer type), huh ? Something else ! See <a href="http://blog.monstuff.com/archives/000037.html" rel="nofollow noreferrer">this</a> and <a href="http://msdn.microsoft.com/fr-fr/library/system.delegate%28v=vs.110%29.aspx" rel="nofollow noreferrer">that</a>.</p>\n'}, {'answer_id': 50314365, 'author': 'Yogesh Prajapati', 'author_id': 4959238, 'author_profile': 'https://Stackoverflow.com/users/4959238', 'pm_score': 1, 'selected': False, 'text': '<p>Some basic here.\n"Delegate" is actually the name for a variable that holds a reference to a method or a lambda</p>\n\n<p>This is a anonymous method - </p>\n\n<pre><code>(string testString) =&gt; { Console.WriteLine(testString); };\n</code></pre>\n\n<p>As anonymous method do not have any name we need a delegate in which we can assign both of these method or expression. For Ex.</p>\n\n<pre><code>delegate void PrintTestString(string testString); // declare a delegate\n\nPrintTestString print = (string testString) =&gt; { Console.WriteLine(testString); }; \nprint();\n</code></pre>\n\n<hr>\n\n<p>Same with the lambda expression. Usually we need delegate to use them</p>\n\n<pre><code>s =&gt; s.Age &gt; someValue &amp;&amp; s.Age &lt; someValue    // will return true/false\n</code></pre>\n\n<p>We can use a func delegate to use this expression.</p>\n\n<pre><code>Func&lt; Student,bool&gt; checkStudentAge = s =&gt; s.Age &gt; someValue &amp;&amp; s.Age &lt; someValue ;\n\nbool result = checkStudentAge ( Student Object);\n</code></pre>\n'}, {'answer_id': 67167690, 'author': 'Ievgen Martynov', 'author_id': 927030, 'author_profile': 'https://Stackoverflow.com/users/927030', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Short version:</strong></p>\n<p>A delegate is a <strong>type</strong> that represents references to methods. C# <strong>lambda</strong> expression is a syntax to create <strong>delegates</strong> or <strong>expression trees</strong>.</p>\n<p><strong>Kinda long version:</strong></p>\n<p>Delegate is not &quot;the name for a variable&quot; as it\'s said in the accepted answer.</p>\n<p>A delegate is a <strong>type</strong> (literally a type, if you inspect IL, it\'s a class) that represents references to methods (<a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/delegates/" rel="nofollow noreferrer">learn.microsoft.com</a>).</p>\n<p><a href="https://i.stack.imgur.com/r0lPp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r0lPp.png" alt="enter image description here" /></a></p>\n<p>This type could be initiated to associate its instance with any method with a compatible signature and return type.</p>\n<pre><code>namespace System\n{\n    // define a type\n    public delegate TResult Func&lt;in T, out TResult&gt;(T arg);\n}\n\n// method with the compatible signature\npublic static bool IsPositive(int int32)\n{\n    return int32 &gt; 0;\n}\n\n// initiated and associate\nFunc&lt;int, bool&gt; isPositive = new Func&lt;int, bool&gt;(IsPositive);\n</code></pre>\n<p>C# 2.0 introduced a syntactic sugar, anonymous method, enabling methods to be defined <strong>inline</strong>.</p>\n<pre><code>Func&lt;int, bool&gt; isPositive = delegate(int int32)\n{\n    return int32 &gt; 0;\n};\n</code></pre>\n<p>In C# 3.0+, the above anonymous method’s inline definition can be further simplified with lambda expression</p>\n<pre><code>Func&lt;int, bool&gt; isPositive = (int int32) =&gt;\n{\n    return int32 &gt; 0;\n};\n</code></pre>\n<p>C# <strong>lambda</strong> expression is a syntax to create <strong>delegates</strong> or <strong>expression trees</strong>. I believe expression trees are not the topic of this question (<a href="https://www.youtube.com/playlist?list=PLRwVmtr-pp06SlwcsqhreZ2byuozdnPlg" rel="nofollow noreferrer">Jamie King about expression trees</a>).</p>\n<p>More could be found <a href="https://weblogs.asp.net/dixin/understanding-csharp-features-5-lambda-expression" rel="nofollow noreferrer">here</a>.</p>\n'}]
['https://Stackoverflow.com/questions/73227', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1538/']