【発行側】
public class class1
{
public delegate void _MyEvent(object sender, MyEventArgs e);
public event _MyEvent MyEvent;
protected virtual void MyChangeEvent(MyEventArgs e)
{
if ( MyEvent != null )
{
MyEvent( this, e );
}
}
private void Changed()
{
MyEventArgs e = new MyEventArgs( arg1, arg2 );
MyChangeEvent(e);
}
public class MyEventArgs : EventArgs
{
public string Arg1;
public int Arg2;
...
public MyEventArgs ( string _Arg1, int _Arg2 )
{
Arg1 = _Arg1;
Arg2 = _Arg2;
}
}
}
【受取側】
public class class2
{
private void Define()
{
class1 obj = new class1();
obj.MyEvent += new class1._MyEvent(RecieveEvent);
}
private void RecieveEvent( object sender, class1.MyEventArgs e)
{
Console.WriteLine(e.Arg1 + e.Arg2);
}
}
0 件のコメント:
コメントを投稿