You can do it with reflection, but in general it is better if you can declare your fields in an array. Instead of:
SomeType field1;
SomeType field2;
SomeType field3;
...
SomeType field6;
You can do this:
SomeType[] fields = new SomeType[6];
Then you can loop over the array setting the values:
for (int i = 0; i < fields.length; ++i)
{
fields[i] = yourValues[i];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…