有人能告诉我怎样才能更好更优雅地重写下面的方法吗?

// 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参数修改器传递DropDownLists的数组:

public static void RefreshAllDropdownlists(params DropDownList[] dropDownLists)
{
    foreach (DropDownList ddl in dropDownLists)
    {
        ddl.ClearSelection();
    }
}

用法与当前方法相同

10-04 12:24