G
Gomaw Beoyr
In C, I do it this way:
void f(
double *a,
double *b,
double *c
) {
if (a)
*a = cumbersome_calculation_of_a();
if (b)
*b = cumbersome_calculation_of_b();
if (c)
*c = cumbersome_calculation_of_c();
}
So what's the way to do it in C#? One of these ways, perhaps?
public void F( // But I don't particularly like this way
bool calcA,
bool calcB,
bool calcC,
out double a,
out double b,
out double c
) {
if (calcA)
a = cumbersomeCalculationOfA();
if (calcB)
b = cumbersomeCalculationOfB();
if (calcC)
c = cumbersomeCalculationOfC();
}
public void F( // And this way REALLY sucks!
ref double? a,
ref double? b,
ref double? c
) {
if (a != null)
a = cumbersomeCalculationOfA();
if (b != null)
b = cumbersomeCalculationOfB();
if (c != null)
c = cumbersomeCalculationOfC();
}
So, which is the "stardard pattern" in C# to do this?
(Please don't reply that I should make it three separate
functions and calls. The actual problems are more complex
than my examples above.)
Gomaw
void f(
double *a,
double *b,
double *c
) {
if (a)
*a = cumbersome_calculation_of_a();
if (b)
*b = cumbersome_calculation_of_b();
if (c)
*c = cumbersome_calculation_of_c();
}
So what's the way to do it in C#? One of these ways, perhaps?
public void F( // But I don't particularly like this way
bool calcA,
bool calcB,
bool calcC,
out double a,
out double b,
out double c
) {
if (calcA)
a = cumbersomeCalculationOfA();
if (calcB)
b = cumbersomeCalculationOfB();
if (calcC)
c = cumbersomeCalculationOfC();
}
public void F( // And this way REALLY sucks!
ref double? a,
ref double? b,
ref double? c
) {
if (a != null)
a = cumbersomeCalculationOfA();
if (b != null)
b = cumbersomeCalculationOfB();
if (c != null)
c = cumbersomeCalculationOfC();
}
So, which is the "stardard pattern" in C# to do this?
(Please don't reply that I should make it three separate
functions and calls. The actual problems are more complex
than my examples above.)
Gomaw