这两个类有什么区别?哪个更可取?
class MulticastExample
{
delegate void ME();
ME me;
public MulticastExample()
{
ME a = new ME(() => Console.WriteLine("A"));
ME b = new ME(() => Console.WriteLine("B"));
me = a + b;
}
public void Run()
{
me();
}
}
-
class ListExample
{
delegate void LE();
List<LE> le = new List<LE>();
public ListExample()
{
LE a = new LE(() => Console.WriteLine("A"));
LE b = new LE(() => Console.WriteLine("B"));
le.Add(a);
le.Add(b);
}
public void Run()
{
foreach (var x in le)
{
x();
}
}
}