Ejemplo n.º 1
0
    static void Main(string[] args)
    {
        List <string>          ptr             = new List <string>();
        AlphaNumbericCollector alphaCollector  = new AlphaNumbericCollector();
        StringCollector        stringCollector = new StringCollector();

        while (true)
        {
            ptr.Add(Console.ReadLine());
            if (ptr[ptr.Count - 1] != null)
            {
                for (int i = 0; i < ptr[ptr.Count - 1].Length; i++)
                {
                    if (ptr[ptr.Count - 1][i] >= 0x30 && ptr[ptr.Count - 1][i] <= 0x39)
                    {
                        AlphaOperation alpha_operation = alphaCollector.CollectingMethod;
                        alpha_operation(ptr[ptr.Count - 1]);
                        alphaCollector.Show();
                        break;
                    }
                    else if (i == ptr[ptr.Count - 1].Length - 1)
                    {
                        StringOperation string_operation = stringCollector.CollectingMethod;
                        string_operation(ptr[ptr.Count - 1]);
                        stringCollector.Show();
                        break;
                    }
                }
            }
            else
            {
                ptr.Remove(ptr[ptr.Count - 1]);
            }
        }
    }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            AlphaNumbericCollector ncollector = new AlphaNumbericCollector();
            StringCollector        acollector = new StringCollector();
            EventInput             input      = new EventInput();

            input.OnProcessed += ncollector.Numberic;
            input.OnProcessed += acollector.String;
            input.Run();
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            AlphaNumbericCollector alphaNumbericCollector = new AlphaNumbericCollector();
            StringCollector        stringCollector        = new StringCollector();
            StringReceiver         stringReceiver         = new StringReceiver();

            Func <string>   PromptRecord  = stringReceiver.EnquireRecord;
            Action <string> ReceiveRecord = stringReceiver.StringReceive;

            string val;

            Console.WriteLine("To finish entering, type: end");
            Console.WriteLine();
            val = PromptRecord();  // stringReceiver.EnquireRecord();


            while (val != "end")
            {
                Predicate <string> isNumberPresent = IsNumberInString;    // Use of Predicate Delegate
                bool numberPresent = isNumberPresent(val);

                if (numberPresent)
                {
                    stringReceiver.StringReceived += alphaNumbericCollector.AddToList;
                }

                else
                {
                    stringReceiver.StringReceived += stringCollector.AddToList;
                }
                ReceiveRecord(val);      //    Used Action type delegate
                val = PromptRecord();    // Used Func type delegate


                if (val == "end")
                {
                    Console.WriteLine();
                    Console.WriteLine("Data recorded in Classes:");
                    Console.WriteLine();

                    DisplayRecords += new EventHandler(alphaNumbericCollector.Dispaly);
                    DisplayRecords += new EventHandler(stringCollector.Dispaly);
                    DisplayRecords.Invoke();

                    Console.ReadKey();
                }
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            StringCollector        sCollector  = new StringCollector();
            AlphaNumbericCollector anCollector = new AlphaNumbericCollector();

            Console.WriteLine("Please enter a string: ");
            Message mes1 = sCollector.Process;
            Message mes2 = anCollector.Process;
            var     s    = Console.ReadLine();

            if (!s.Any(c => char.IsDigit(c)))
            {
                mes1(s);
            }
            else
            {
                mes2(s);
            }
            Console.ReadKey();
        }