Created
December 5, 2014 12:37
-
-
Save snippe/9f2c7216b3731cdf1bcf to your computer and use it in GitHub Desktop.
Different forms of Lambda Expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
delegate int Delegate1(); | |
delegate int Delegate2(int a); | |
delegate int Delegate3(int a, int b); | |
static void Main(string[] args) | |
{ | |
//No parameters | |
Delegate1 del1 = () => PrintValue(); | |
int val1 = del1(); //1 | |
//One parameter | |
Delegate2 del2 = x => x * x; | |
int val2 = del2(2); //4 | |
//Multiple parameters | |
Delegate3 del3 = (x, y) => x * y; | |
int val3 = del3(2, 3); //6 | |
} | |
static int PrintValue() | |
{ | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment