Assuming the following method:
int ExtractMedian(int Statistic)
{
return ExtractionWork;
}
Is it possible to force Statistic to accept only odd numbers like 1, 3, 5 by using ref for example but without checking the value after it is passed?
Is it possible to force
Statisticto accept only odd numbers like1, 3, 5by usingreffor example but without checking the value after it is passed?
No, I don't think so.
I would simply check at the start of the method:
int ExtractMedian(int Statistic)
{
if(Statistic % 2 == 0)
throw new ArgumentException("Statistic must be odd");
return ExtractionWork;
}
No, there is no way to do that.
Code Contracts COULD be used to force this - but they are basically a post processing step in code that then can get used by an analyzer to see an invalid call. They are NOT part of the integral .NET functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With