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;
- using System.Threading.Tasks;
- namespace App1b
- {
- class Manager<T>
- {
- private const int SIZE = 5;
- private T[] entities;
- private int counter = 0;
- public Manager()
- : this(SIZE)
- { }
- public Manager(int size)
- {
- this.entities = new T[size];
- }
- public void AddEntity(T entity)
- {
- if (counter >= entities.Length) {
- throw new InvalidOperationException("The stack is full");
- }
- entities[counter] = entity;
- counter++;
- }
- public T RemoveEntity()
- {
- if (counter == 0) {
- throw new InvalidOperationException("The stack is empty");
- }
- 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