解决方案
我们可以使用反射来获取属性并调用它。比如:
object result = theObject.GetType().GetProperty("Property" + i).GetValue(theObject, null);
获取"Property1", "Property2", "Property3"的值
或者使用原型函数来做到这一点:
void something(int i, string P1) {
something(i, P1, String.Empty);
}
void something(int i, string P1, string P2) {
something(i, P1, P2, String.Empty);
}
void something(int i, string P1, string P2, string P3) {
something(i, P1, P2, P3, String.Empty);
}
日期:2020-03-24 21:59:50 来源:oir作者:oir
