title: Can I pass an anonymous object into a method that expects a reference parameter of type object?
body: <p>I'd like to know why the first call to <code>Bar(ref object)</code> doesn't work and the second one does. Seems silly considering I'm passing in a type <code>object</code> either way, <strong>and</strong> passing in an anonymous type to <code>Foo(object)</code> works fine. Why would <code>ref</code>, something that has to do with memory location influence the calls to <code>Bar()</code>?</p>
  
  <p>Consider the following snippet:</p>
  
  <pre><code>static void Foo(object obj)
  { }
  
  static void Bar(ref object obj)
  { }
  
  static void Main()
  {
      // Compiles
      var a = new { };
      Foo(a);
  
      // Does not compile
      var b = new { };
      Bar(ref b);
  
      // Compiles
      object c = new { };
      Bar(ref c);
  }
  </code></pre>
  
  <p>I see in the answers below suggestions on how to make the code compile, but that's not what I'm after. I'd like to know specifically why making it a <code>ref</code> parameter prevents compilation when passing in an anonymous type to <code>Foo()</code> worked fine.</p>