title: Function as an argument to a method
body: <p>You can do anonymous functions in C# like you can in JavaScript:</p>
  
  <p>JavaScript:</p>
  
  <pre><code>var s = (function ()
  {
      return "Hello World!";
  }());
  </code></pre>
  
  <p>C#:</p>
  
  <pre><code>var s = new Func&lt;String&gt;(() =&gt;
  {
      return "Hello World!";
  })();
  </code></pre>
  
  <p>... In JavaScript you can pass functions to be executed by other functions. On top of that; you can pass parameters to the function which gets executed:</p>
  
  <pre><code>var f = function (message) // function to be executed
  {
      alert(message);
  };
  
  function execute(f) // function executing another function
  {
      f("Hello World!"); // executing f; passing parameter ("message")
  }
  </code></pre>
  
  <p>Is the above example possible in C#?
  <br /><br /><br />
  <strong>Update</strong></p>
  
  <p>Use-case: I am iterating over a bunch of database, logging specific entities. Instead of calling my second function (<code>F()</code>) inside <code>Log()</code> of <code>Logger</code>, I'd like to call <code>F()</code> outside the class.</p>
  
  <p>... Something along the lines of:</p>
  
  <pre><code>public void F(String databaseName)
  {
  }
  
  public class Logger
  {
      public void Log(Function f)
      {
          var databaseName = "";
  
          f(databaseName);
      }
  }
  </code></pre>