为什么以下代码不打印"Hello,World!"?
using System;
namespace Test
{
public class Program
{
public static void Main(string[] args)
{
var a = new A();
var b = new B(a);
b.Evnt += val => Console.WriteLine(val);
a.Do();
}
}
public class A
{
public void Do()
{
Evnt("Hello, World!");
}
public event Action<string> Evnt = v => {};
}
public class B
{
public B(A a)
{
a.Evnt += Evnt; // this does not work
}
public event Action<string> Evnt = v => {};
} …Run Code Online (Sandbox Code Playgroud)