using System; using System.Collections.Generic; using System.Linq; public class DemoFunc { private Func intFunc; private Func AsFunc(T input) { return () => input; } private T Exec(Func func) { return func(); } public void ContrivedMethod() { Func helloWorldFunc = AsFunc("Hello World!"); var helloWorld = Exec(helloWorldFunc); // helloWorld == "Hello World!" intFunc = AsFunc(1); var one = Exec(intFunc); // one == 1); } public void SomewhatMoreRealisticMethod() { // cant use var - because we need to tell the compiler what we'll describe Func, string, bool> authorExists = (booksByAuthor, authorName) => booksByAuthor.Any(ba => ba.Author == authorName); Func, string, BooksByAuthor> getGataloguedAuthor = (booksByAuthor, authorName) => { // can do complex stuff or help in debugging return booksByAuthor.FirstOrDefault(ba => ba.Author == authorName); }; var bas = Enumerable.Empty();// for conciceness var exits = authorExists(bas, "Homer"); var homersBooks = getGataloguedAuthor(bas, "Homer"); } }