title: How does LINQPad compile code?
body: <p>I am guessing it neither invokes csc.exe or implement an entire compiler, so how does it work?</p>
  
  <p>Update: Thanks to Jon Skeet for the pointer to code that was easy to learn from.</p>
  
  <pre><code>string c = @"
  public class A
  {
      public static void Main(string[] args)
      {
          System.Console.WriteLine(""hello world"");
      }
  }
  ";
  
  CodeDomProvider compiler = new CSharpCodeProvider();
  
  CompilerParameters parameters = new CompilerParameters();
  parameters.WarningLevel = 4;
  parameters.GenerateExecutable = false;
  parameters.GenerateInMemory = true;
  
  CompilerResults r = compiler.CompileAssemblyFromSource(parameters, c);
  
  Assembly a = r.CompiledAssembly;
  
  Type[] ts = a.GetTypes();
  
  Type t = ts[0];
  
  object o = t.GetMethod("Main").Invoke(null, new object[] { new string[] { } });
  </code></pre>