2 つのクラスがあり、これらのクラス間で通信するためのイベントを作成する必要があります。
Class a
{
public delegate void delegat(int a);
public event delegat exit;
...
private void a_FormClosed(object sender, FormClosedEventArgs e)
{
// My event named exit should run here, but I get exception!
exit(100);
}
}
Class b
{
a instance=new a();
a.exit+=new a.delegat(my_fun);
...
private void my_fun(int x)
{
if(x==100)
do_smth;
...
}
}
しかし、問題は、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」という例外が発生することです。私は何が間違っているのか理解できませんか?これの新しいインスタンスをどこで作成する必要がありますか? 手伝ってくれてありがとう!