public static void Main(string[] args) { // tạo 1 đối tượng delegate IntegerToInteger ii = new IntegerToInteger(Calculator.Add); // tham chieu den ô nhớ của hàm ii += Calculator.Subtract; // nạp thêm hàm vào chuỗi thực hiện của delegate - multicast ii += new Calculator().division; int a = ii(5, 2); // thực thi các hàm được nạp vào delegate Console.WriteLine("a = " + a); // Calculator.Add(2 , 5); // Calculator.Subtract(2 , 5); // // luon can chay 2 dong voi moi cap so // Calculator.Add(7 , 3); // Calculator.Subtract(7 , 3); TaxMoney tm = TaxCalc.GetTax("VN");// tm la 1 delegate; float tax = tm(100000000); Console.WriteLine("Thue phai nop: " + tax); // tạo 1 hàm ẩn danh bằng delegate TaxMoney tm2 = delegate(float salary) { return(salary * 40 / 100); }; float frTax = tm2(10000); Console.WriteLine("Thue tai Phap: " + frTax); }
public static void Main(string[] args) { IntegerToInteger ii = new IntegerToInteger(Caculator.Add); ii += Caculator.Subtract; ii += new Caculator().Division; ii(2, 5); TaxMoney tm = TaxCaic.GetTax("US");// tm la 1 delegate float tax = tm(100000000); Console.WriteLine("thue phai nop " + tax); //tao 1 ham an danh bang delegate TaxMoney tm2 = delegate(float salary) { return(salary * 40 / 100); }; float frTax = tm2(10000); Console.WriteLine("thue tai phap " + frTax); PhepTinh pt = Pheptinh.GetPt("-"); int c = pt(2, 3); Console.WriteLine("ket qua " + c); }
public static void Main(string[] args) { // tao 1 doi tuong delegate IntegerToInteger ii = new IntegerToInteger(Calculator.Add); // tham chiu den o nho cua ham ii += Calculator.Subtract; //nap them chuoi thuc hien cua delegate mo ii += Calculator.division; int a = ii(5, 2); // Thực thi các ham nạp bào delegate Console.WriteLine("a =" + a); // Calculator.Add(2, 5); //Calculator.Subtract(2, 5); //luon chay 2 dong voimoi cap //Calculator.Add(7, 3); //Calculator.Subtract(7, 3); TaxMoney tm = TaxCalc.GetTax("VN");// tm là 1 delegate; float tax = tm(1000000); Console.WriteLine("Thue phai nop:" + tax); TaxMoney tm2 = delegate(float salary) { return(salary * 40 / 100); }; float frTax = tm2(10000); Console.WriteLine("Thue tai Phap:" + frTax); }
public static void Main1(string[] args) { // tao doi tuong delegate IntegerToInteger ii = new IntegerToInteger(Calculator.Add); ii += Calculator.Subtract; // nap them ham vao chuoi thuc hien cura delegate - multi catch ii += new Calculator().division; ii(15, 5); // thuc thi cac ham duoc nap vao delegate //Console.WriteLine("a =" + a); //Calculator.Add(2, 5); //Calculator.Subtract(2, 5); //luon can chay 2 dong voi moi cap so TaxMoney tm = TaxCalc.GetTax("VN"); //tm la delegate float tax = tm(1000000000); Console.WriteLine("Thue phai nop: " + tax); //Tao 1 ham an danh bang delegate TaxMoney tm2 = delegate(float salary) { return(salary * 40 / 100); }; float frTax = tm2(10000); Console.WriteLine("Thue tai Phap: " + frTax); }
public static void Main(string[] args) { //tạo 1 đối tượng delegate IntegerToInteger ii = new IntegerToInteger(Calculator.Add);//tham chiếu đến ô nhớ của hàm //program.Add(2, 4); ii += Calculator.Subtract; //nạp thêm hàm vào chuỗi thực hiện của delegate ii += new Calculator().division; ii(5, 2); //thực thi các hàm nạp vào delegate //Calculator.Add(2, 6); //Calculator.Subtract(4, 6); //Calculator.Add(7, 3); //Calculator.Subtract(4, 3); TaxMoney tm = TaxCalc.GetTax("VN");//tm la 1 delegate float tax = tm(100000000); Console.WriteLine("thue phai nop :" + tax); TaxMoney tm2 = delegate(float salary) { return(salary * 40 / 100); }; float frTax = tm2(10000); Console.WriteLine("Thue tai phap :" + frTax); }