title: Converting the value of a string to a variable of KeyValuePair<TKey,TValue>
body: <p>I was doing something like this :</p>
  
  <pre><code>foreach( KeyValuePair&lt;int,SOME_CLASS&gt; reader in _readerDict )
  {
    var selectedReader = reader;
  
    var antenna1 = selectedReader.Value.Antenna1IsEnabled;
    var antenna2 = selectedReader.Value.Antenna2IsEnabled;
    var antenna3 = selectedReader.Value.Antenna3IsEnabled;
    var antenna4 = selectedReader.Value.Antenna4IsEnabled;
  }
  </code></pre>
  
  <p>But then again I want to do something like the following :</p>
  
  <pre><code>foreach( KeyValuePair&lt;int,SOME_CLASS&gt; reader in _readerDict )
  {
    var selectedReader = reader;
  
    for( var idx = 1; idx &lt;= 4; idx++ )
    {
      var antennaIsEnabled = string.Format( "selectedReader.Value.Antenna{0}IsEnabled", idx );
  
      // cast the value of antennaIsEnabled as a KeyValuePair&lt;int,SOME_CLASS&gt; variable datatype here
      ....
    }
  }
  </code></pre>
  
  <p>Is there anyway for me to cast the value of antennaIsEnabled as a KeyValuePair variable datatype?</p>