日期:2014-05-20  浏览次数:20796 次

怎样给静态类定义事件?
public   class   Hash
{
                public     static   Hashtable   ht=new     Hashtable();
                  public   static   void   addHash(string   code,Socket   sock)
                {
                      。。。。。。
                }
}
我希望给Hash类定义一个事件(afterAdd),每执行了addHash方法,就触发afterAdd事件。请问代码怎么写?

------解决方案--------------------
类似如下的代码就是了:
public class Hash
{
public static event EventHandler <EventArgs> afterAdd;

public static System.Collections.Hashtable ht = new System.Collections.Hashtable();
public static void addHash(string code, System.Net.Sockets.Socket sock)
{
if (afterAdd != null)
{
afterAdd(null, new EventArgs());
}
}
}