delegate keyword pre lambda
Context: Before C# 3.0, anonymous methods were written using the delegate keyword. They can still be used but are largely superseded by lambdas.
Syntax
Section titled “Syntax”delegate(parameters) { statements }Examples
Section titled “Examples”Action<string> print = delegate(string msg){ Console.WriteLine(msg);};
Func<int, int> doubleIt = delegate(int x){ return x * 2;};Capturing outer variables
Section titled “Capturing outer variables”Same as lambdas: they create closures.
int factor = 3;Func<int, int> multiply = delegate(int x) { return x * factor; };Real-world usage example
Section titled “Real-world usage example”Compatibility with C# 2.0: If you need to write code that compiles on .NET Framework 2.0, you must use anonymous methods instead of lambdas.
Example: In some legacy ASP.NET WebForms, you might still see delegate used in event handlers.