Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace OOP9
- {
- class Manager<T>
- {
- private const int LIMIT = 5;
- T[] entities;
- private int counter;
- public Manager()
- : this(LIMIT)
- {}
- public Manager(int limit)
- {
- entities = new T[limit];
- counter = 0;
- }
- public void Add(T entity)
- {
- if (counter >= entities.Length)
- {
- throw new InvalidOperationException("The limit has been reached");
- }
- entities[counter] = entity;
- counter++;
- }
- public T Remove()
- {
- if (counter == 0)
- {
- throw new InvalidOperationException("No entities");
- }
- T temp = entities[counter - 1];
- entities[counter - 1] = default(T);
- counter--;
- return temp;
- }
- public int GetNumberOfEntities()
- {
- return counter;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement