事件处理 在线等待....
--------------------编程问答--------------------using System;--------------------编程问答-------------------- ouyang4683 你这个和我写的有啥区别?
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication2
{
public class testA
{
private testB _tb;
public testA()
{
this._tb = new testB();
this._tb.onB+=new testB.onBHander(onB);
this._tb.exec();
}
private void onB(object sender, string a)
{
Console.WriteLine(a);
}
}
public class testB
{
public delegate void onBHander(object sender, string a);
public event onBHander onB;
private testC _tc;
public testB()
{
if(this._tc==null)
this._tc = new testC();
this._tc.onC += new testC.onCHandler(onC);
}
public void exec()
{
this._tc.test1();
}
private void onC(object sender, string a)
{
if (onB != null)
{
onB(sender, a);
}
}
}
public class testC
{
public delegate void onCHandler(object sender, string a);
public event onCHandler onC;
public void test1()
{
if (onC != null)
onC(this, "a");
}
}
}
感觉这样写很乱 --------------------编程问答-------------------- testA能不能直接订阅testC的事件呢? --------------------编程问答-------------------- 只是改了你代码里的错
能 你都用的public 类
testA里声明个 testC就行
补充:.NET技术 , C#