Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Stage_1_Kurs_Work_Seydametov
- {
- public class BusList : IEnumerable<Bus>
- {
- private Bus[] buses;
- private int count;
- public int Count { get { return count; } private set { count = value; } }
- public BusList(int amount)
- {
- buses = new Bus[amount];
- }
- public Bus this[int i]
- {
- get
- {
- return buses[i];
- }
- set
- {
- buses[i] = value;
- }
- }
- public Bus Add(Bus bus)
- {
- if (count < buses.Length)
- {
- buses[count] = bus;
- count++;
- }
- return bus;
- }
- public bool Remove(Bus bus)
- {
- var ind = buses.ToList().IndexOf(bus);
- if (ind >= 0)
- {
- buses[ind] = null;
- for (int i = ind; i < buses.Length - 1; i++)
- {
- buses[i] = buses[i + 1];
- }
- buses[buses.Length - 1] = null;
- return true;
- }
- return false;
- }
- public Bus[] GetBuses()
- {
- return buses;
- }
- public IEnumerator<Bus> GetEnumerator()
- {
- return buses.Take(count).GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement