Example #1
0
        private void EqualButton_Click(object sender, RoutedEventArgs e)
        {
            double newNumber;

            if (double.TryParse(resultLabel.Content.ToString(), out newNumber))
            {
                switch (selectedOperator)
                {
                case Operator.Addition:
                    result = MathLogic.Addition(lastNumber, newNumber);
                    break;

                case Operator.Subtraction:
                    result = MathLogic.Subtraction(lastNumber, newNumber);
                    break;

                case Operator.Multiplication:
                    result = MathLogic.Multiplication(lastNumber, newNumber);
                    break;

                case Operator.Division:
                    result = MathLogic.Division(lastNumber, newNumber);
                    break;
                }
                resultLabel.Content = result.ToString();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            MathLogic m = new MathLogic();

            m.CircleArea(5.5);
            m.Add(45, 65);
        }
Example #3
0
        static void Main(string[] args)
        {
            // 2. Instantiate a delegate
            //DelShapes ds = new DelShapes(ShapeArea.CircleArea);

            /*DelShapes ds = ShapeArea.CircleArea;
             * ds += ShapeArea.SquareArea;//InvocationList - FIFO
             * ds -= ShapeArea.CircleArea;
             * //3. Invocation of Delegates
             * //ds.Invoke(3);//old way invoking delegates
             * ds();*/

            //Predefined delegates in C#
            //1. Action- Delegate of type void
            // Delegate tied to a named Method
            //delAct += ShapeArea.CircleArea;

            //Delegate is tied to an anonymous method
            Action <double> delAct;

            /*delAct = delegate (double radius)
             * {
             *  double area = Math.PI * radius * radius;
             *  Console.WriteLine($"Area of a circle with radius {radius} cm is {area}");
             * };*/


            //delAct += ShapeArea.SquareArea;

            /*delAct += delegate (double s)
             * {
             *  double area = s * s;
             *  Console.WriteLine($"Area of a Square with side {s} cm is {area}");
             * };*/

            delAct = (r) => {
                double v = Math.PI * r * r;
                Console.WriteLine(v);
            };

            //delAct(6);
            //2. Func - Delegate of return type
            Func <double, double, double> DelFunc = ShapeArea.RectArea;
            //Console.WriteLine($"Area of rectangle is {DelFunc(4,8)}");

            MathLogic            m            = new MathLogic();
            Func <int, int, int> DelCalculate = (a, b) => a + b;

            /*DelCalculate = m.Add;
             * DelCalculate += m.Sub;
             * DelCalculate +=m.Multiply;
             * DelCalculate +=m.Divide;
             * DelCalculate -= m.Divide;*/
            Console.WriteLine(DelCalculate(5, 6));
            //3. Predicate - a delgate of type bool

            //Anonymous Methods
        }
 public void PercentageTest(double expected, double val)
 => Assert.AreEqual(expected, MathLogic.ConvertToPercent(val));
 public void DivideTest(double expected, double val1, double val2) =>
 Assert.AreEqual(expected, MathLogic.Divide(val1, val2));
 public void MultiplyTest(double expected, double val1, double val2)
 => Assert.AreEqual(expected, MathLogic.Multiply(val1, val2));
 public void SubtractTest(double expected, double val1, double val2)
 => Assert.AreEqual(expected, MathLogic.Subtract(val1, val2));
 public void AddTest(double expected, double val1, double val2)
 => Assert.AreEqual(expected, MathLogic.Add(val1, val2), Delta);
Example #9
0
 public static double CircleArea(this MathLogic m, double r)
 {
     return(Math.PI * r * r);
 }
Example #10
0
 public void XNORTest()
 {
     TestLogicOperator(new float[] { 1, 1, 0, 0 }, new float[] { 1, 0, 1, 0 }, new float[] { 1, 0, 0, 1 }, (a, b) => MathLogic.XNOR(a, b), "xnor");
 }
Example #11
0
 public void NANDTest()
 {
     TestLogicOperator(new float[] { 1, 1, 0, 0 }, new float[] { 1, 0, 1, 0 }, new float[] { 0, 1, 1, 1 }, (a, b) => MathLogic.NAND(a, b), "nand");
 }
Example #12
0
 public void NOTTest()
 {
     TestLogicOperator(new float[] { 1, 0 }, new float[] { 0, 0 }, new float[] { 0, 1 }, (a, b) => MathLogic.NOT(a), "not");
 }