K
Ken Durden
I'm looking for a way to simulate the following kind of C code:
--- C++ ---
void F( double * array, double * fMean, double * fMedian, double *
fMax, double * fMin );
--- C# ---
void F( double[] array, out double fMean, out double fMedian, out
double fMax, out double fMin );
I've read some of the examples on using overrides to simulate default
values, but that's not exactly what I'm doing here. On the client
side, NULL would be specified to indicate that (for example) mean and
median aren't needed, but max and min are.
Now, I can certainly use use overloads to have 2^4 -1 versions of this
function. This would provide a maximally efficient way to calculate
all these statistics; however, I don't need that, and the code
duplication would kill me. Furthermore, the function above is just an
example of the concept, the real code is more complex, of course.
I could also pass a boolean next to each out parameter indicating
whether to calculate it or not.
I could also pass a structure, etc...
I was kinda hoping I could pass in null for one of those output
parameters, but then I realized there wouldn't be any way to check on
the other side.
I could also declare all the parameters as objects, pass in nulls for
the ones I don't want, unbox the ones which were requested.
Any other options? Which one of the above makes the most sense?
Many Thanks,
-ken
--- C++ ---
void F( double * array, double * fMean, double * fMedian, double *
fMax, double * fMin );
--- C# ---
void F( double[] array, out double fMean, out double fMedian, out
double fMax, out double fMin );
I've read some of the examples on using overrides to simulate default
values, but that's not exactly what I'm doing here. On the client
side, NULL would be specified to indicate that (for example) mean and
median aren't needed, but max and min are.
Now, I can certainly use use overloads to have 2^4 -1 versions of this
function. This would provide a maximally efficient way to calculate
all these statistics; however, I don't need that, and the code
duplication would kill me. Furthermore, the function above is just an
example of the concept, the real code is more complex, of course.
I could also pass a boolean next to each out parameter indicating
whether to calculate it or not.
I could also pass a structure, etc...
I was kinda hoping I could pass in null for one of those output
parameters, but then I realized there wouldn't be any way to check on
the other side.
I could also declare all the parameters as objects, pass in nulls for
the ones I don't want, unbox the ones which were requested.
Any other options? Which one of the above makes the most sense?
Many Thanks,
-ken