请个位高手帮忙看看下面这段代码错在那里!为什么没有结果
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
//方法代理
public delegate void SendBingDelegate(int[] Number); /// <summary>
/// 程序入口
/// </summary>
class Program
{
public static void Main(string[] args)
{
send ev = new send();
BinEvent bin = new BinEvent();
bin.GetBinEvent();
ev.GetEvent();
}
} /// <summary>
/// 调用事件
/// </summary>
public class send
{
public event SendBingDelegate SendBingEvent;
public void GetEvent()
{
int[] st = new int[20];
for (int i = 0; i < 20; i++)
{
st[i] = i + i;
} if (SendBingEvent != null)
SendBingEvent(st); }
}public class BinEvent
{
/// <summary>
/// 为事件绑定方法
/// </summary>
EventPrope ep = new EventPrope();
public void GetBinEvent()
{
ep.SendBingEvent += new SendBingDelegate(GetAnd);
} private void GetAnd(int[] Number)
{
int and = 0;
foreach (int item in Number)
{
and += item;
}
Console.WriteLine(and);
Console.ReadLine();
}
}
public class EventPrope
{
/// <summary>
/// 事件访问器
/// </summary>
send Cevent = new send();
public event SendBingDelegate SendBingEvent
{
add
{
Cevent.SendBingEvent += value;
}
remove
{
Cevent.SendBingEvent -= value;
}
}
}}
BinEvent bin = new BinEvent();
bin.GetBinEvent();
ev.GetEvent();
public class EventPrope
{
/// <summary>
/// 事件访问器
/// </summary>
send Cevent = new send();此
public event SendBingDelegate SendBingEvent
{
add
{
Cevent.SendBingEvent += value;
}
remove
{
Cevent.SendBingEvent -= value;
}
}
}此实例非彼实例~~~
send Cevent = new send();
这里有问题,
应该将send ev = new send();
ev传到EventPrope而不是new一个。