有人能告诉我怎样才能更好更优雅地重写下面的方法吗?
// in class------------------
public static void RefreshAllDropdownlists(DropDownList ddlRemoveUsersFromRole, DropDownList ddlAddUsersToRole, DropDownList ddlAddAllUsersToRole, DropDownList ddlRemoveAllUsersFromRole, DropDownList ddlDeleteAllUsersFromRole)
{
ddlRemoveUsersFromRole.ClearSelection();
ddlAddUsersToRole.ClearSelection();
ddlAddAllUsersToRole.ClearSelection();
ddlRemoveAllUsersFromRole.ClearSelection();
ddlDeleteAllUsersFromRole.ClearSelection();
}
// in codebehind------------------
UserGvUtil.RefreshAllDropdownlists(ddlRemoveUsersFromRole, ddlAddUsersToRole, ddlAddAllUsersToRole, ddlRemoveAllUsersFromRole, ddlDeleteAllUsersFromRole);
谢谢您!
最佳答案
使用params
参数修改器传递DropDownList
s的数组:
public static void RefreshAllDropdownlists(params DropDownList[] dropDownLists)
{
foreach (DropDownList ddl in dropDownLists)
{
ddl.ClearSelection();
}
}
用法与当前方法相同