Created
February 14, 2013 20:36
-
-
Save yetanotherchris/4956179 to your computer and use it in GitHub Desktop.
Func examples in C#
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
Func<string, bool> funcMethod1 = name => name == "bob"; // non-bracketed version of method1 | |
Func<string, bool> funcMethod2 = delegate(string name) | |
{ | |
return name == "bob"; | |
}; | |
Func<string, bool> funcMethod3 = new Func<string, bool>(IsBob); | |
Func<string, bool> funcMethod4 = IsBob; // Shorthand for the above | |
bool isFuncBob1 = method1("bob"); | |
bool isFuncBob2 = method2("bob"); | |
bool isFuncBob3 = method3("bob"); | |
Console.WriteLine(isFuncBob1); | |
Console.WriteLine(isFuncBob2); | |
Console.WriteLine(isFuncBob3); | |
Console.ReadLine(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment