S
Shmuel Cohen
I have a class holding some enumerated types, i.e.,
public class MyEnums
{
public enum DATA_ITEM {FIRST, SECOND, THIRD,FOURTH,FIFTH};
...
}
And I have a class the contains data, for example:
public class TheData
{
double a, b, c;
int d,e;
...
}
public class MyDataClass
{
List<TheData> myData;
public List<TheData> MYDATA
{
get {return myData; }
...
}
...
}
I want to write a utility function as follows
public class Utility {
private double adder (List<TheData> data, FIELD fld) --> ???
{
double val = 0.0;
foreach (...)
{
val += data.fld; --> ????
}
}
public static SUM_DATA (MyDataClass mdc, MyEnums.DATA_ITEM di)
{
// Determine the field to sum up
switch (di)
{
case MyEnums.DATA_ITEM.FIRST:
return adder (mdc.MYDATA, FIELD a); --> ????
case MyEnums.DATA_ITEM.SECOND:
return adder (mdc.MYDATA, FIELD b); --> ????
}
}
Basically, I want to get the field to add up, and pass this information
to the private "adder" function, along with the
proper field to use - I'd like to avoid summing up the items in a
switch() statement because each data array is quite large.
Any ideas on how to properly implement this?
Thanks!
public class MyEnums
{
public enum DATA_ITEM {FIRST, SECOND, THIRD,FOURTH,FIFTH};
...
}
And I have a class the contains data, for example:
public class TheData
{
double a, b, c;
int d,e;
...
}
public class MyDataClass
{
List<TheData> myData;
public List<TheData> MYDATA
{
get {return myData; }
...
}
...
}
I want to write a utility function as follows
public class Utility {
private double adder (List<TheData> data, FIELD fld) --> ???
{
double val = 0.0;
foreach (...)
{
val += data.fld; --> ????
}
}
public static SUM_DATA (MyDataClass mdc, MyEnums.DATA_ITEM di)
{
// Determine the field to sum up
switch (di)
{
case MyEnums.DATA_ITEM.FIRST:
return adder (mdc.MYDATA, FIELD a); --> ????
case MyEnums.DATA_ITEM.SECOND:
return adder (mdc.MYDATA, FIELD b); --> ????
}
}
Basically, I want to get the field to add up, and pass this information
to the private "adder" function, along with the
proper field to use - I'd like to avoid summing up the items in a
switch() statement because each data array is quite large.
Any ideas on how to properly implement this?
Thanks!