//public InvokeList() //{ // // 绑定一组抽象方法 // handlers = new List<StringAssignmentEventHandler>(); // handlers.Add(AppendHello); // handlers.Add(AppendComma); // handlers.Add(AppendWorld); //} //// 具体操作方法 //public void AppendHello() { message[0] = "hello"; } //public void AppendComma() { message[1] = ","; } //public void AppendWorld() { message[2] = "world"; } //public void Invoke() //{ // foreach (StringAssignmentEventHandler handler in handlers) // handler(); //} #endregion #region Anonymous Method Constructor Common Version //public InvokeList() //{ // // 绑定一组抽象方法 // handlers = new List<StringAssignmentEventHandler>(); // StringAssignmentEventHandler h1 = delegate { message[0] = "hello"; }; // StringAssignmentEventHandler h2 = delegate { message[1] = ","; }; // StringAssignmentEventHandler h3 = delegate { message[2] = "world"; }; // handlers.Add(h1); // handlers.Add(h2); // handlers.Add(h3); //} //public void Invoke() //{ // foreach (StringAssignmentEventHandler handler in handlers) // handler(); //} #endregion #region Anonymous Method Constructor Simple Version public InvokeList() { StringAssignmentEventHandler handler = null; handler += delegate { message[0] = "hello"; }; handler += delegate { message[1] = ","; }; handler += delegate { message[2] = "world"; }; handler.Invoke(); }
public MulticastDelegateInvoker() { StringAssignmentEventHandler handler = null; handler += new StringAssignmentEventHandler(AppendHello); handler += new StringAssignmentEventHandler(AppendComma); handler += new StringAssignmentEventHandler(AppendWorld); handler.Invoke(); }
public InvokeListEvolution() { StringAssignmentEventHandler handler = null; handler += delegate { message[0] = "Hello"; }; handler += () => { message[1] = ","; }; handler += () => { message[2] = "world."; }; handler.Invoke(); }
public InvokeList() { StringAssignmentEventHandler handlers = null; handlers += delegate { _message[0] = "Hello"; }; handlers += delegate { _message[1] = " "; }; handlers += delegate { _message[2] = "World"; }; handlers.Invoke(); }
public void MulticastDelegateInvoke() { StringAssignmentEventHandler handler = null; handler += new StringAssignmentEventHandler(AppendHello); handler += new StringAssignmentEventHandler(AppendComma); //handler += new StringAssignmentEventHandler(AppendWorld); //handler += delegate { message[2] = "world"; }; handler += () => { message[2] = "world"; }; handler.Invoke(); }