小编spr*_*sty的帖子

为什么delgate类型的属性不起作用?

有人可以解释为什么这段代码不起作用?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        public delegate void Something(string s);

        public class TestDelegate
        {
            public Something something
            {
                set
                {
                    Console.WriteLine("Registering delegate: {0}", something);
                    something = value;
                    Console.WriteLine("Delegate registered: {0}", something);
                }

                get
                {
                   Console.WriteLine("Get delegate");
                   return something;
                }
            }

            public void doSomething(string s)
            {
                something(s);
            }
        }

        static void Main(string[] args)
        {
            TestDelegate td = new TestDelegate();
            td.something = (string s) => Console.WriteLine(s);
            td.doSomething("test");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# delegates properties

0
推荐指数
1
解决办法
71
查看次数

标签 统计

.net ×1

c# ×1

delegates ×1

properties ×1