private void submit_Click(object sender, EventArgs e) { int num1 = int.Parse(txtNum1.Text); int num2 = int.Parse(txtNum2.Text); //namespace.classname Calculator.CalculatorBOL cal = new CalculatorBOL(); switch (Fnoperator) { case "+": ArithmaticOperation op1 = new ArithmaticOperation(cal.Add); op1(num1, num2); break; case "-": ArithmaticOperation op2 = new ArithmaticOperation(cal.Sub); op2(num1, num2); break; case "*": ArithmaticOperation op3 = new ArithmaticOperation(cal.Mult); op3(num1, num2); break; case "/": ArithmaticOperation op4 = new ArithmaticOperation(cal.Div); op4(num1, num2); break; } int result = cal.Result; label1.Text = result.ToString(); }
static void Main(string[] args) { Console.WriteLine("enter choice: \n 1.ADD \n 2.SUB \n 3.MULT \n 4.DIV \n"); int choice = int.Parse(Console.ReadLine()); Console.WriteLine("enter num1:"); int num1 = int.Parse(Console.ReadLine()); Console.WriteLine("enter num2:"); int num2 = int.Parse(Console.ReadLine()); CalculatorBOL cal = new CalculatorBOL(); switch (choice) { case 1: ArithmaticOperation op1 = new ArithmaticOperation(cal.Add); op1(num1, num2); Console.WriteLine("addition is"); break; case 2: ArithmaticOperation op2 = new ArithmaticOperation(cal.Sub); op2(num1, num2); Console.WriteLine("subtraction is"); break; } int result = cal.Result; Console.WriteLine(result); Console.ReadLine(); }
private void submit_Click(object sender, EventArgs e) { int num1 = int.Parse(textBox1.Text); int num2 = int.Parse(textBox2.Text); Cal1.CalBOL cal = new CalBOL(); switch (foperator) { case "+": ArithmaticOperation op1 = new ArithmaticOperation(cal.Add); op1(num1, num2); break; case "-": ArithmaticOperation op2 = new ArithmaticOperation(cal.Sub); op2(num1, num2); break; case "*": ArithmaticOperation op3 = new ArithmaticOperation(cal.Mul); op3(num1, num2); break; case "/": ArithmaticOperation op4 = new ArithmaticOperation(cal.Div); op4(num1, num2); break; } int result = cal.Result; label1.Text = result.ToString(); }
void RefershAll() { this.fisrtOperand = 0.0; this.txtMonitor.Text = "0"; intStream = true; dotPressed = false; currentOperation = ArithmaticOperation.None; }
public MainForm() { InitializeComponent(); intStream = true; currentOperation = ArithmaticOperation.None; fisrtOperand = 0.0; ResetMemory(); dotPressed = false; }
static void OnMultiplication(IAsyncResult itfAR) { //it is like a handler Console.WriteLine("SubComplete() invoked on thread {0}.", Thread.CurrentThread.ManagedThreadId); Console.WriteLine("Your subtraction is complete"); // Now get the result. AsyncResult ar = (AsyncResult)itfAR; ArithmaticOperation b = (ArithmaticOperation)ar.AsyncDelegate; Console.WriteLine("20 - 10 is {0}.", b.EndInvoke(itfAR)); // Retrieve the informational object and cast it to string string msg = (string)itfAR.AsyncState; Console.WriteLine(msg); }
static void Main(string[] args) { Console.WriteLine("***** AsyncCallbackDelegate Example *****"); Console.WriteLine("Main() invoked on thread {0}.", Thread.CurrentThread.ManagedThreadId); ArithmaticOperation b = new ArithmaticOperation(Sub); IAsyncResult iftAR = b.BeginInvoke(20, 10, new AsyncCallback(OnSubtraction), "Main() thank you for subtracting these numbers."); // Assume other work is performed here... Console.ReadLine(); }
static void Main() { //how to write anonymous method: 1 Func <int, int, int> add = (a, b) => (a + b); ArithmaticOperation <int, int> addOperation = delegate(int x, int y) { return(x + y); }; //addOperation(12, 3); //how to write anonymous method: 2 (Lambda syntax/Lambda) => Lambda operator //2007 (.net framework - 3.0/ C# - 3.0) ArithmaticOperation <double, double> multiplyOperation = (a, b) => (a * b); //ArithmaticOperation multiplyOperation = new ArithmaticOperation((a, b) => (a * b)); ArithmaticOperation <long, long> subtractOperation = (m, n) => { return(m - n); }; Calculate <int, int>(addOperation, 12, 3); Calculate <double, double>(multiplyOperation, 12.4, 3.2); Calculate <long, long>(subtractOperation, 12234, 3456); }
private void btnDivide_Click(object sender, EventArgs e) { this.PutStringOnScreen(this.CalculateResult().ToString()); Button currentButton = (Button)sender; if (currentButton == this.btnPlus) { this.currentOperation = ArithmaticOperation.Addition; } else if (currentButton == this.btnMultiply) { this.currentOperation = ArithmaticOperation.Multiplication; } else if (currentButton == this.btnDivide) { this.currentOperation = ArithmaticOperation.Division; } else if (currentButton == this.btnSubtract) { this.currentOperation = ArithmaticOperation.Subtraction; } this.intStream = false; dotPressed = false; }
static void Calculate <TIn, TOut>(ArithmaticOperation <TIn, TOut> operation, TIn a, TIn b) { Console.WriteLine(operation(a, b)); }