您的位置:首页 > 编程语言 > C#

c# event事件编译后变成了什么?

2015-05-27 14:59 260 查看
源码:

        public delegate void wt();

        public void f1()

        {

            MessageBox.Show("a");

        }

        public event wt sj;

        public Form1()

        {

            InitializeComponent();

            sj+=new wt(f1);

            sj();

        }

或写成

            sj+=new wt(f1);

            sj.Invoke();

编译后:

        public delegate void wt();

        public void f1()

        {

            MessageBox.Show("a");

        }
        private wt sj;

        public event wt sj

        {

            add

            {

                wt wt2;

                wt sj = this.sj;

                do

                {

                    wt2 = sj;

                    wt wt3 = (wt) Delegate.Combine(wt2, value);

                    sj = Interlocked.CompareExchange<wt>(ref this.sj, wt3, wt2);

                }

                while (sj != wt2);

            }

            remove

            {

                wt wt2;

                wt sj = this.sj;

                do

                {

                    wt2 = sj;

                    wt wt3 = (wt) Delegate.Remove(wt2, value);

                    sj = Interlocked.CompareExchange<wt>(ref this.sj, wt3, wt2);

                }

                while (sj != wt2);

            }

        }


        public Form1()

        {

            this.InitializeComponent();

            this.sj += new wt(this.f1);

            this.sj();

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐