Ejemplo n.º 1
0
 //Заполнение коллекции рандомными элементами
 public MyCollection(int Count)
 {
     Count = ExceptionHandlingArray.TestSize(Count);
     arr   = new TranspSredstv[Count];
     for (int i = 0; i < Count; i++)
     {
         this.Add(RandElem.Rand());
     }
 }
Ejemplo n.º 2
0
        ////для обращения к элементу класса через свойство
        //public int Current
        //{
        //    get { return current; }
        //    set
        //    {
        //        if (value < 0 || value >= Capacity) throw new IndexOutOfRangeException();
        //        else current = value;
        //    }
        //}
        ////обращение к элементу класса с индексом current
        //public T Item
        //{
        //    get
        //    {
        //        if (Current >= Count) throw new Exception("значение Current не может быть больше, чем значение индекса последнего элемента.");
        //        else return arr[Current];
        //    }
        //    set
        //    {
        //        if (value is T) arr[Current] = value;
        //        else throw new InvalidCastException();
        //    }
        //}

        //Итератор

        public T this[int index]
        {
            get
            {
                index = ExceptionHandlingArray.TestIndex(index + 1, Count);
                return(arr[index - 1]);
            }
            set
            {
                index          = ExceptionHandlingArray.TestIndex(index + 1, Count);
                arr[index - 1] = value;
            }
        }
Ejemplo n.º 3
0
 //Индексатор
 public TranspSredstv this[int index]
 {
     get
     {
         index = ExceptionHandlingArray.TestIndex(index, Count);
         return(arr[index]);
     }
     set
     {
         index      = ExceptionHandlingArray.TestIndex(index, Count);
         arr[index] = value;
         CollectionReferensCenged?.Invoke(this, new CollectionHandlerEventArgs(NameCollection,
                                                                               String.Format("Изменен элемент коллекции с индексом {0}.", index + 1), arr[index]));
     }
 }
        public MyCollections(int size_city)
        {
            size_city = ExceptionHandlingArray.TestSize(size_city);

            city     = new MyList <TranspSredstv>();
            terminal = new MyList <TranspSredstv>();

            for (int i = 0; i < size_city; i++)
            {
                TranspSredstv buf = RandElem.Rand();
                city.Add(buf);
                if (rand.Next(1, 3) == 2)
                {
                    terminal.Add(buf);
                }
            }
        }