Beispiel #1
0
        static void Main()
        {
            int[] A = new int[] { 1, 2, 3 };

            int[] B = SquareArray(A);
            PrintArray(B); //1,4,9

            int[] C = IncrementArray(A);
            PrintArray(C); //2,3,4

            int[] D = ApplyOperation(A, Square);
            PrintArray(D); //1,4,9
            int[] E = ApplyOperation(A, TimesTen);
            PrintArray(E); //10,20,30

            MickeyMouse times100 = delegate(int x) { return(x * 100); };

            int[] F = ApplyOperation(A, times100); //100,200,300

            MickeyMouse times100b = delegate(int x) { return(TimesN(x, 100)); };

            int[] G = ApplyOperation(A, times100b); //100,200,300

            int[] H = ApplyOperation(A, delegate(int x) { return(x * 100); });

            int[] I = ApplyOperation(A, (int x) => { return(x * 100); });
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            int[] A = new int[] { 1, 2, 3 };
            int[] B = SquareArray(A);
            printArray(B);

            int[] C = IncrementArray(A);
            printArray(C);

            int[] D = ApplyOperation(A, Square);
            printArray(D);

            int[] E = ApplyOperation(A, TimesTen);
            printArray(E);

            int[] F = ApplyOperation(A, Sqrt);
            printArray(E);

            MickeyMouse Times100 = delegate(int x) { return(x * 100); };

            int[] M = ApplyOperation(A, Times100);//100,200,300

            MickeyMouse times100b = delegate(int x) { return(TimesN(x, 100)); };

            int[] G = ApplyOperation(A, times100b);//100,200,300

            int[] H = ApplyOperation(A, delegate(int x) { return(x * 100); });

            int[] I = ApplyOperation(A, (int x) => { return(x * 100); });//lambda expression
        }
Beispiel #3
0
 static int[] ApplyOperation(int[] A, MickeyMouse ops)
 {
     int[] newArray = new int[A.Length];
     for (int i = 0; i < A.Length; i++)
     {
         newArray[i] = ops(A[i]); //applying ops to each element
     }
     return(newArray);
 }