static void Main(string[] args)
        {
            int    delegatesNum = 10;
            Random r            = new Random();

            RandomDelegate[] rand = new RandomDelegate[delegatesNum];

            for (int i = 0; i < delegatesNum; i++)
            {
                rand[i] = delegate()
                {
                    return(r.Next(100));
                };
            }


            DelegateArray delArray = delegate(RandomDelegate[] randArray)
            {
                int sum = 0;

                for (int i = 0; i < delegatesNum; i++)
                {
                    sum += randArray[i]();
                }

                return(sum / delegatesNum);
            };

            Console.WriteLine("Average value: {0}", delArray(rand));
            Console.ReadKey();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var del_arr = new RandomDelegate[] { Random_Num, Random_Num };

            FinalDelegate del = delegate(Delegate[] delegates)
            {
                var            result = 0;
                RandomDelegate temp;
                for (int i = 0; i < delegates.Length - 1; i++)
                {
                    temp    = (RandomDelegate)delegates[i];
                    result += temp();
                }
                return(result);
            };

            Console.WriteLine(del(del_arr));
        }
Beispiel #3
0
 /// <summary>
 /// OS - w/l/m. isInfect - 1/0. rand - random delegate.
 /// </summary>
 /// <param name="operationSystem"></param>
 /// <param name="isInfect"></param>
 /// <param name="isRand"></param>
 public Computer(char operationSystem, int isInfect, RandomDelegate rand)
 {
     this.Random = rand;
     if (operationSystem == 'w')
     {
         this.OperationSystem = OS.Windows;
     }
     if (operationSystem == 'l')
     {
         this.OperationSystem = OS.Linux;
     }
     if (operationSystem == 'm')
     {
         this.OperationSystem = OS.Mac;
     }
     this.Virus = (isInfect == 1);
     probability = 0;
 }
Beispiel #4
0
 public string CallSomeFunction(RandomDelegate fun)
 {
     return(fun("Aimal Khan's delegate"));
 }