各位高手:
    我想法是这样子滴:
      代码:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            run(1);
        }
        static void run(int i)
        {
            Del d = new Del();
            d.eve += new Del.DelEvent(d_eve);
            Console.Read();
        }
        static void d_eve(int i)
        {
            Console.WriteLine("a");
        }
    }
    class Del
    {
        delegate void DelEvent(int i);
        public event DelEvent eve;    }
}我想做的是,如何做才能使一运行run(int i)这方法,这个事件就马上执行,这要怎么实现呢。
因为这个事件与Del类中的属性变量等值没有关连,所以不能在属性值改变时引发这事件(我只知道这样引发事件)
还有其它方法吗

解决方案 »

  1.   

     static void run(int i) 
            { 
                Del d = new Del(); 
                d.eve += new Del.DelEvent(d_eve); 
                d.eve(i);
                Console.Read(); 
            } 
      

  2.   

    class Program
        {
            static void Main(string[] args)
            {
                 run(1);
            }
            static void run(int i)
            {
                Del d = new Del();
                d.eve += new Del.DelEvent(d_eve);
                d.Do(i);
                Console.Read();
            }
            static void d_eve(int i)
            {
                Console.WriteLine(i);
                Console.ReadLine();
            }
        }
        class Del
        {
            public delegate void DelEvent(int i);
            public event DelEvent eve;
            public void Do(int i)
            {
                if (eve != null)
                    eve(i);
            }    }
      

  3.   

    2楼,,d.eve(i);
    这样加上去出错吧。。
      

  4.   

    Sorry,弄错了using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                run(1);
            }
            static void run(int i)
            {
                Del d = new Del();
                d.eve += new DelEvent(d_eve);
                d.mymethod(i);
                Console.Read();
            }
            static void d_eve(int i)
            {
                Console.WriteLine(i);
                Console.WriteLine("a");
            }
        }
        delegate void DelEvent(int i);
        class Del
        {
            
             public event DelEvent eve;         public void mymethod(int i)
             {
                 eve(i);
             }    }
    }