예제 #1
0
        public INode AddFirstNode()
        {
            List <IOperator> operators = new List <IOperator>();

            Console.WriteLine("\n1.x\n" +
                              "2.skaičių\n" +
                              "3.cos(ax+b)\n" +
                              "4.sin(ax+b)\n" +
                              "5.e^ax+b\n" +
                              "6.ln(ax+b)\n" +
                              "(\n"
                              );
            Console.Write(equation);
            string choice = Console.ReadLine();

            switch (choice)
            {
            case "1":
                AddOperationToNode(CreateX(), operators);
                break;

            case "2":
                AddOperationToNode(CreateNumber(), operators);
                break;

            case "3":
                AddOperationToNode(CreateCosX(), operators);
                break;

            case "4":
                AddOperationToNode(CreateSinX(), operators);
                break;

            case "5":
                AddOperationToNode(CreateEx(), operators);
                break;

            case "6":
                AddOperationToNode(CreateLnX(), operators);
                break;

            case "(":
                equation += "(";
                OpenParenthesis item = new OpenParenthesis(accuracy, riba);
                item.equation = equation;
                var ri = item.AddFirstNode();
                equation = item.equation;
                AddOperationToNode(ri, operators);
                break;

            default:
                Console.WriteLine("nera tokio pasirinkimo");

                break;
            }
            DoOperations s = new DoOperations(operators);

            return(s.SimplifyNodes());
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(
                @"C# delegates are similar to pointers to functions, in C or C++. 
With the help of deletgates, methods can be passed as a parameter to another methods.
A delegate is a reference type variable that holds the reference to a method. 
The reference can be changed at runtime.");

            Console.WriteLine(Environment.NewLine);

            Console.WriteLine(@"Following example shows a delegate DoOperations. It is used 
to perform various operations on 2 integers like add, subtract and multiply.");
            Console.WriteLine(Environment.NewLine);

            DoOperations add = new DoOperations(Add);

            Console.WriteLine("Addition 2+3 = " + add(2, 3));

            DoOperations subtract = Subtract;

            Console.WriteLine("Subtraction 2-3 = " + subtract(2, 3));

            result = 1;
            DoOperations multiply = Multiply;

            Console.WriteLine("Multiplication 2*3 = " + multiply(2, 3));

            Console.WriteLine(Environment.NewLine);


            Console.WriteLine(@"This is multicast delegate. When delegate is invoked, seris of methods will be invoked.
In this case, first Add method and then Multiply method will be invoked.");
            add += multiply;

            Console.WriteLine("Result 2+3 = 5; 5*(2*3) = : " + CallBackMethod(add, 2, 3));


            Console.ReadKey();
        }
예제 #3
0
        static int CallBackMethod(DoOperations doOperations, int a, int b)
        {
            result = doOperations(a, b);

            return(result);
        }