仅传递接受的参数值的方法

Exp*_*sam 3 c# parameters methods parameter-passing

假设以下方法:

int ExtractMedian(int Statistic)
{
    return ExtractionWork;
}
Run Code Online (Sandbox Code Playgroud)

有可能强制Statistic只接受奇数,比如1, 3, 5使用ref例如但是在传递后不检查值吗?

Mat*_*sen 8

有可能强制Statistic只接受奇数,比如1, 3, 5 使用ref例如但是在传递后不检查值吗?

不,我不这么认为.

我只想检查方法的开头:

int ExtractMedian(int Statistic)
{
    if(Statistic % 2 == 0)
        throw new ArgumentException("Statistic must be odd");

    return ExtractionWork;
}
Run Code Online (Sandbox Code Playgroud)