static void setLogin() { string login = "******"; LengthLogin lengthLoginDelegate = s => s.Length; LengthLogin lengthLoginDelegate2 = (string s) => { return(s.Length); }; //LengthLogin lengthLoginDelegate3 = (string s) => { return s.Length; }; //блочные лямба выражения BoolPassword bp = (s1, s2) => { return(true); }; bool res = bp.Invoke("", ""); Console.WriteLine(res); int lengthLogin = lengthLoginDelegate(login); }
static void Main(string[] args) { SetLogin(); Console.Write("Введите пароль: "); string password1 = Console.ReadLine(); Console.Write("Повторите пароль: "); string password2 = Console.ReadLine(); // Используем лямбда выражение BoolPassword bp = (s1, s2) => s1 == s2; if (bp(password1, password2)) { Random ran = new Random(); string resCaptha = ""; for (int i = 0; i < 10; i++) { resCaptha += (char)ran.Next(0, 100); } Console.WriteLine("Введите код xD: " + resCaptha); string resCode = Console.ReadLine(); // Реализуем блочное лямбда-выражение Captha cp = (s1, s2) => { if (s1 == s2) { Console.WriteLine("Регистрация удалась!"); } else { Console.WriteLine("Не переживай, в следующий раз получится :)"); } return; }; cp(resCaptha, resCode); } else { Console.WriteLine("Регистрация провалилась. Пароли не совпадают"); } Console.ReadLine(); }
static void Main(string[] args) { SetLogin(); Console.Write("Enter password: "******"Repeat password: "******"Registration succes!"); } else { Console.WriteLine("Registration failed. Passwords don't match"); } Console.ReadLine(); }
static void Main() { SetLogin(); Console.Write("Parol engiz : "); string password1 = Console.ReadLine(); Console.Write("Paroldy kaytala : "); string password2 = Console.ReadLine(); BoolPassword bp = (s1, s2) => s1 == s2; if (bp(password1, password2)) { Console.WriteLine("Satti tirkeldi !"); } else { Console.WriteLine("Tirkelmedi. Paroldar saykes kelmeydi !"); } Console.ReadLine(); }
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(); }