How to use a variable to access an object member in c#
<p>I have a web service that returns a custom object (a struct type) <code>APIStruct user</code>.
I have a variable holding the name of the current field it is checking for <code>currentField</code>.</p>

<p>Now, in a situation where <code>user</code> contains <code>first_name</code> and <code>last_name</code>, I can access the value using <code>user.first_name</code> or <code>user.last_name</code>. BUT, is it possible to hold the field name in a variable and access the value through the variable? working like: </p>

<pre><code>var currentField = "first_name";
var value = user.currentField;
</code></pre>

<p>Obviously the above is not working, so is there any way to do this? In the past with languages such as PowerShell it works just like above <code>$currentField = "first_name"; $value = user.$currentField</code></p>

<p>I've tried <code>user.currentField</code> <code>user.(currentField)</code> <code>user[currentField]</code> <code>user.$currentField</code></p>