I currently have to load some properties in a List like this:
List<TestClass> test = new List<TestClass>(); // Loaded with data
// Get calculated values back as double[]
double[] calculatedValues = CalculateValue(test);
// Add the calculated values to the List<TestClass> test object
for (int i = 0; i < test.Count; i++)
{
test[i].Value = calculatedValues[i];
}
public int[] CalculateValue(List<TestClass> testClass)
{
int[] output = int[testClass.Count];
// Some calculation
return output;
}
public class TestClass
{
public string Name { get; set; }
public int Value { get; set; }
}
What I really would like to do is something like this:
public static List<TestClass> CalculateValue(List<TestClass> testClass, string property)
{
double[] output = double[testClass.Count];
// Some calculation
// output to testClass
// like:
// testClass.property = output
// Would then be like: testClass.Value = output
return testClass;
}
I would like to tell my method which property it should be added to. Is it possible in some way?
EDIT: Lets say I have Value2, Value3, Value4 etc. in my TestClass. Then I can not hardcode my CalculateValue method to always add to the "Value" property. Hope it makes sense
Hope it makes sense.
Best regards