public void Do() { _t1 += (s) => { Console.WriteLine($"1: {s}"); return(true); }; _t1 += (s) => { Console.WriteLine($"2: {s}"); return(true); }; _t1 += (s) => { Console.WriteLine($"3: {s}"); throw null; }; _t1 += (s) => { Console.WriteLine($"4: {s}"); return(true); }; try { _t1("invoke"); } catch { } //1: invoke //2: invoke //3: invoke _t1.GetInvocationList().ToList().ForEach(d => { try { (d as SomeDelegate).Invoke("from list"); } catch { } }); //1: from list //2: from list //3: from list //4: from list }
static void Main() { SomeDelegate del = null; SomeDelegate staticDelegate = new SomeDelegate(SomeClass.SomeStaticMethod); staticDelegate("Привет Мир!"); SomeClass someObj = new SomeClass(); staticDelegate += someObj.SomeInstanceMethod;; staticDelegate("Мир Привет!"); staticDelegate += SomeClass.SomeStaticMethod; del += SomeClass.SomeStaticMethod; del += someObj.SomeInstanceMethod; foreach (SomeDelegate item in del.GetInvocationList()) { item("Привет Мир!"); } SomeDelegate someDelegate = delegate(String arg) { Console.WriteLine(arg); }; someDelegate("ChupaChups"); Console.ReadKey(); string login = "******", password1 = "E=mc^2", password2 = "E=mc^2", resCapcha = "asd", resCode = "asd1"; LengthLogin ll = ss => ss.Length; int longlogin = ll(login); BoolPassword bp = (s1, s2) => s1 == s2; if (bp(password1, password2)) //Checking password { Console.WriteLine("Регистрация удалась!"); } else { Console.WriteLine("Регистрация провалилась. Пароли не совпадают"); } Console.ReadKey(); Capcha cp = (s1, s2) => { if (s1 == s2) { Console.WriteLine("Регистрация удалась!"); } else { Console.WriteLine("Не переживай, в следующий раз получится :)"); } return; }; cp(resCapcha, resCode);//Checking capcha Console.ReadKey(); }