title: How can I get a value of a property from an anonymous type?
body: <p>I have a datagrid populated by a Linq query. When the focused row in the datagrid changes I need to set a variable equal to one of the properties in that object.</p>
  
  <p>I tried...</p>
  
  <pre><code>var selectedObject = view.GetRow(rowHandle);
  _selectedId = selectedObject.Id;
  </code></pre>
  
  <p>... but the compiler doesn't care for this at all ("Embedded statement cannot be a declaration or labled statement").</p>
  
  <p>It seems like the property should be easy to access.  Inspecting the object during runtime shows all the properties I expect, I just don't know how to access them.</p>
  
  <p>How can I get access to the anonymous object's property?</p>
  
  <p><strong>Edit for Clarifications:</strong></p>
  
  <p>I happen to be using DevExpress XtraGrid control. I loaded this control with a Linq query which was composed of several different objects, therefore making the data not really conforming with any one class I already have (ie, I cannot cast this to anything).</p>
  
  <p>I'm using .NET 3.5.</p>
  
  <p>When I view the results of the view.GetRow(rowHandle) method I get an anonymous type that looks like this:</p>
  
  <pre><code>{ ClientId = 7, ClientName = "ACME Inc.", Jobs = 5 }
  </code></pre>
  
  <p>My objective is to get the ClientId from this anonymous type so I can do other things (such as a load a form with that client record in it).</p>
  
  <p>I tried a couple of the suggestions in the early answers but was unable to get to a point where I could get this ClientId.</p>