public void Zero(char item, bool isInput) { if (isInput) { numbers = "0"; result = "0"; op = '.'; invoker.Invoke(numbers); currentState = CalcStates.Zero; } else { if (nonzerodigits.Contains(item)) { AccumulateDigits(item, true); } else if (separators.Contains(item)) { AccumulateDigitsWithDecimal(item, true); } else if (zero.Contains(item)) { Zero(item, true); } } }
public void InsertStaff() { Console.OutputEncoding = Encoding.UTF8; Console.Write("Nhập tên: "); string name = Console.ReadLine(); Console.Write("Nhập ngày sinh((MM/dd/yyyy): "); string date = Console.ReadLine(); DateTime birthday = default(DateTime); if (date != "") { birthday = DateTime.Parse(date); } Console.WriteLine("Giới tính: \t1.Nữ \t2.Nam"); GenderType gender; ConsoleKeyInfo choice = Console.ReadKey(true); if (choice.KeyChar == '1') { gender = GenderType.Nu; } else if (choice.KeyChar == '2') { gender = GenderType.Nam; } else { gender = GenderType.Khong; } Console.WriteLine("Danh sách các bộ phận:"); OnPrintListDepartment.Invoke(false); Console.Write("\nNhập ID bộ phận: "); int idjob = Int32.Parse(Console.ReadLine()); Console.Write("Nhập số CMND: "); string CMND = Console.ReadLine(); Console.Write("Nhập tiền lương của nhân viên: "); int salary = Int32.Parse(Console.ReadLine()); staff_control.CreateStaffInfo(name, birthday, gender, idjob, CMND, salary); Console.WriteLine("Nhấn enter để nhập tiếp ..."); ConsoleKeyInfo choice3 = Console.ReadKey(true); if (choice3.Key == ConsoleKey.Enter) { InsertStaff(); } else { Console.Clear(); intro.ShowListFunction(); } }
public static void UpdateHeadline(string headline) { currentHeadline = headline; if (newsDel != null) { newsDel.Invoke(currentHeadline); } }
public static void RunDemo() { //Executing a Print function using delegate SimplePrintDel spd = Print; spd.Invoke(); //Executing a parameteric function using delegate PrintDelegate pd = Print; string msg = "This is another way of calling parametric delegate"; pd.Invoke(msg); //Executing a complex parametric function using delegate PrintGrades pgd = ShowGrades; pgd.Invoke(StudentGrades.Intermdiate); pgd.Invoke(StudentGrades.Advanced); pgd.Invoke(StudentGrades.Standard); //Multicasting Delegates pd += Print2; pd += Print3; pd.Invoke("Multi-Casting...."); //C# delegates ActionDel = Print; ActionDel2 = Print; ActionDel(); ActionDel2("Action Del 2"); //Retrun value delegate SumDel sum = Sum; var rv = sum.Invoke(10, 400); Console.WriteLine("Value : " + rv); FuncDel = Sum; rv = FuncDel.Invoke(103, 500); Console.WriteLine("Value : " + rv); Console.ReadKey(); }
private static void Main(string[] args) { //ConnectAzureRepos(); ToStringDelegate toString = PrintToString; Student Biggo = new Student("Biggo"); Dog Bingo = new Dog(45); toString(Bingo); toString(Biggo); PrintDelegate delegatedPrint = PrintInt; delegatedPrint(32); delegatedPrint = PrintMoney; //can also be called with the Invoke Method delegatedPrint.Invoke(45); PrintHelper(delegatedPrint, 7000); delegatedPrint = PrintInt; PrintHelper(delegatedPrint, 7000); //multicast delegates PrintDelegate multiPrintDelegate = PrintInt; multiPrintDelegate += PrintMoney; multiPrintDelegate += PrintHexadecimal; //call the delegate and all the methods associated with it multiPrintDelegate(500); //multiCast multiplication MathDelegate delegatedMath = Add; delegatedMath += Subtract; delegatedMath += Multiply; delegatedMath += Divide; delegatedMath(500, 2); PairDelegate(); Console.ReadLine(); }
public void ListReceiptFunction() { while (true) { Console.Clear(); Console.OutputEncoding = Encoding.UTF8; Console.WriteLine("Nhấn phím số tương ứng để chọn chức năng:"); Console.WriteLine("\t1.\tTạo hóa đơn"); Console.WriteLine("\t2.\tIn hóa đơn"); Console.WriteLine("\t3.\tXóa hóa đơn"); Console.WriteLine("\t4.\tSửa hóa đơn"); Console.WriteLine("\tEsc.\tQuay lại Intro"); ConsoleKeyInfo choice = Console.ReadKey(true); Console.Clear(); switch (choice.Key) { case ConsoleKey.D1: Console.Write("\nBạn chọn Tạo hóa đơn\n"); OnPrintMenu.Invoke(false); InsertReceipt(); break; case ConsoleKey.D2: Console.Write("\nBạn chọn In hóa đơn\n"); receipt_control.PrintReceiptsList(true); Console.WriteLine("\nNhấn phím bất kì để thoát"); Console.ReadKey(); break; case ConsoleKey.D3: Console.WriteLine("\nBạn chọn Xóa hóa đơn\n"); DeleteReceipt(); break; case ConsoleKey.D4: Console.WriteLine("\nBạn chọn Sửa hóa đơn\n"); EditReceipt(); break; case ConsoleKey.Escape: Console.Clear(); intro.ShowListFunction(); break; default: Console.WriteLine("Bạn đã nhập sai. Vui lòng nhập lại"); continue; } } }
public void Print(string msg) { Thread.Sleep(2000); printDelegate.Invoke(msg); }
public void CalcSum(int[] arr) { pd.Invoke(arr); }
public void PrintOK() { pd.Invoke(); }