我正在做这样的事情:
foreach( KeyValuePair<int,SOME_CLASS> 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;
}
但话又说回来,我想做以下事情:
foreach( KeyValuePair<int,SOME_CLASS> reader in _readerDict )
{
var selectedReader = reader;
for( var idx = 1; idx <= 4; idx++ )
{
var antennaIsEnabled = string.Format( "selectedReader.Value.Antenna{0}IsEnabled", idx );
// cast the value of antennaIsEnabled as a KeyValuePair<int,SOME_CLASS> variable datatype here
....
}
}
无论如何,我是否可以将天线IsEnabled 的值转换为 KeyValuePair 变量数据类型?