Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.