Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            MissingNum missingNum = delegate(int[] array)
            {
                return(Enumerable.Range(1, 10).Except(array).Last());
            };
            int missNumberOne   = missingNum(new int[] { 7, 2, 3, 6, 5, 9, 1, 4, 8 });
            int missNumberTwo   = missingNum(new int[] { 1, 2, 3, 4, 6, 7, 8, 9, 10 });
            int missNumberThree = missingNum(new int[] { 10, 5, 1, 2, 4, 6, 8, 3, 9 });

            Console.WriteLine(missNumberOne + " " + missNumberTwo + " " + missNumberThree);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int[] mass1 = new int[] { 7, 5, 10, 2, 4, 6, 8, 3, 9 };

            MissingNum missNum = delegate(int[] mass)
            {
                Array.Sort(mass);
                for (int i = 0; i < mass.Length; i++)
                {
                    if (mass[i] != i + 1)
                    {
                        return(i + 1);
                    }
                }
                return(10);
            };

            Console.WriteLine(missNum(mass1));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            // Create an anonymous method that takes a string as its argument and returns the string in reversed order.

            Reverse reverse = delegate(string text)
            {
                char[] temp = text.ToCharArray();
                Array.Reverse(temp);
                return(new string(temp));
            };

            Console.WriteLine(reverse("Hello word"));
            Console.WriteLine(reverse("The quick brown fox"));

            // . Create a function an anonymous method that takes an array of numbers between 1 and 10 (excluding one number) and returns the missing number.
            MissingNum missingNum = delegate(int[] num)
            {
                Array.Sort(num);
                int miss = 0;
                for (int i = 0; i < num.Length; i++)
                {
                    if (num[i] != i + 1)
                    {
                        miss = i + 1;
                        break;
                    }
                }
                return(miss);
            };

            int print = missingNum(new[] { 1, 2, 3, 4, 6, 7, 8, 9, 10 });

            Console.WriteLine($"Missing number is {print} ");

            print = missingNum(new[] { 10, 5, 1, 2, 4, 6, 8, 3, 9 });
            Console.WriteLine($"Missing number is {print} ");


            Console.ReadLine();
        }