0

キーワードDropDownListをスローするための拡張メソッドがあります。拡張メソッドを使用した例をたくさん見てきたので、理由はよくわかりません。Extension method can only be declared in non-generic, non-nested static classesthisDropDownList

public static class DropDownListExtensions {
    public static void populateDropDownList(this DropDownList source, Action delegateAction) {
        source.DataValueField = "Key";
        source.DataTextField = "Value";
        source.DataSource = delegateAction;
        source.DataBind();
    }
}
4

1 に答える 1

3

おそらく、あなたのDropDownListExtensionsクラスは他のクラスのネストとして宣言されています。名前空間レベルに移動します。

于 2012-06-06T12:46:10.870 に答える