Page.aspx:
<a href="#" <%= ToggleUiVisibility(new List<bool>() { true, true, false }) %> >
link
</a>
C#:
public string ToggleUiVisibility(List<bool> conditions)
{
return conditions.Any(x=>!x) ? "style=\"display:none;\"" : string.Empty;
}
我想知道是否可以做类似(伪代码)的事情
ToggleUiVisibility(true, true, argsN);
public string ToggleUiVisibility(args)
{
// make sure each argument is a bool and trigger the same
// functionality as above
}
最佳答案
使用params关键字:
public string ToggleUiVisibility(params bool[] values)
{
// make sure each argument is a bool and trigger the same
// functionality as above
}
然后可以像下面这样调用您的方法:
ToggleUiVisibility(true, false, ...);
关于c# - 方法参数的动态长度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19838685/