有人可以解释为什么这段代码不起作用吗?
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");
}
}
}