Visual Studio 2010 SP1 の
WPF + C# アプリケーション開発で,
Dictionary の初期化で悩んでいます.
private void function01(UIElement content, EventHandler e)
{
// 処理
}
private void function02(UIElement content, EventHandler e)
{
// 処理
}
という関数があるとして,Dictionary で int と紐付けしたいと考えています.
このとき,Dictionary の宣言時に
private readonly Dictionary<int, Action<UIElement, EventHandler>> FunctionMap = new Dictionary<int, Action<UIElement, EventHandler>>
{
{
1,
function01
},
{
2,
function02
}
};
とすると,下記のように静的でないメソッドは参照できないと言われてしまいます.
エラー 1 A field initializer cannot reference the non-static field, method, or property
それぞれの関数内は静的ではない処理をおこなうため,
function01 などを static で宣言することができません.
このような場合どうしたらよいでしょうか.