Exemplo n.º 1
0
 public MyIterator(MyArray myit)
 {
     this._myIt = myit;
 }
Exemplo n.º 2
0
        private static void Main(string[] args) // client
        {
            string       ints    = "Ints.txt";
            string       floats  = "Floats.txt";
            string       strings = "Strings.txt";
            string       line;
            int          count    = 0;
            int          choice   = 0;
            MyArray      _myArray = new MyArray();
            StreamReader _streamReader;
            IIterator    I = _myArray.CreateIterator();
            IIterator    F = new FilterIterator(I);

            Console.WriteLine("Press 1 to display  even integers (1).");
            Console.WriteLine("Press 2 to filter out even floating point numbers (2)");
            Console.WriteLine("Press 3 to see strings with numbers in them");
            Console.WriteLine();



            choice = Convert.ToInt32(Console.ReadLine());

            switch (choice)
            {
            case 1:
                _streamReader = new StreamReader(ints);
                while ((line = _streamReader.ReadLine()) != null)
                {
                    _myArray[count] = line;
                }
                break;

            case 2:
                _streamReader = new StreamReader(floats);
                while ((line = _streamReader.ReadLine()) != null)
                {
                    _myArray[count] = line;
                }
                break;

            case 3:
                _streamReader = new StreamReader(strings);
                while ((line = _streamReader.ReadLine()) != null)
                {
                    _myArray[count] = line;
                }
                break;

            default:
                Console.WriteLine("Please select 1 or 2");
                Console.WriteLine();

                break;
            }

            for (F.CurrentItem(); !F.IsDone(); F.Next())
            {
                Console.WriteLine(F.CurrentItem());
            }


            Console.ReadLine();
        }