using System.Collections.Generic;
using System.Diagnostics;
static List<string> pooledObjects;
static string objectToPool="bullet ";
static int amountToPool = 20;
public static void Main()
Program p = new Program();
Console.WriteLine("Running ObjectPool");
pooledObjects = new List<string>();
for(int i = 0; i < amountToPool; i++)
tmp += objectToPool + i + " inactive";
Console.WriteLine("created " + i);
static string GetPooledObject()
Console.WriteLine("Running GetPooledObject");
for(int i = 0; i < amountToPool; i++)
if(pooledObjects[i].Contains("inactive"))
Console.WriteLine("found inactive bullet #" + i + ", setting it active and returning");
pooledObjects[i] = pooledObjects[i].Replace("inactive", "active");
Console.WriteLine("Bullet " + i + " already active");
Console.WriteLine("Pulling trigger..");
string tmp = (GetPooledObject());
Console.WriteLine("GUNSHOT");
BulletRecycler((int)Char.GetNumericValue(tmp[7]));
void BulletRecycler(int i)
var sw = Stopwatch.StartNew();
while (sw.Elapsed < TimeSpan.FromSeconds(1))
System.Threading.Thread.Sleep(50);
pooledObjects[bulletN] = pooledObjects[bulletN].Replace("active", "inactive");
Console.WriteLine(bulletN + " inactivated");