Advertisement
ivandrofly

Chaining Actions in C#

Feb 17th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Chains_And_Exceptions
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Action del = new Action(Moo) + BeNaughty + Goo;
  10.             Action del = (Action)(Moo) + BeNaughty + Goo;
  11.             foreach (Action a in del.GetInvocationList())
  12.             {
  13.                 try
  14.                 {
  15.                     a();
  16.                 }
  17.                 catch { }
  18.             }
  19.         }
  20.  
  21.         static void Moo() { Console.WriteLine("Moo()"); }
  22.         static void BeNaughty() { throw new Exception();  }
  23.         static void Goo() { Console.WriteLine("Goo()"); }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement