Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created February 14, 2013 20:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yetanotherchris/4956179 to your computer and use it in GitHub Desktop.
Save yetanotherchris/4956179 to your computer and use it in GitHub Desktop.
Func examples in C#
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