use*_*429 4 c# parameters methods default-value
当该参数为字典类型时,如何为操作设置默认参数值?
例如:
public void Test(Dictionary<int, bool> dic) {
...
}
Run Code Online (Sandbox Code Playgroud)
你不能按照你想要的方式给它一个默认值,因为它必须是一个编译时常量值,但你可以这样做:
private static bool Test(Dictionary<string, string> par = null)
{
if(par == null) par = GetMyDefaultValue();
// Custom logic here
return false;
}
Run Code Online (Sandbox Code Playgroud)