List to drop old items when it reaches a limit.

I use a List .

What I want to do is to , save player input states for 1 second( int = stateID, string = input state), and then pack the latest 6 saved items into a dictionary. This thing would loop.

The list should be taking in 60 entries, and when it reaches 60 it should drop the oldest one and add a new one at the end of the list.

Use a queue so it is automatically solved. The first is always the oldest as you can only Enqueue and Dequeue.

So that simply goes as :

object [] SetQueueOnInput(object newObject)
{
     queue.Enqueue(newObject);  // Add the new object
     if(queue.Count < 60)
     {
         return;     // We do not have 60 items in the queue, we quit
     }
     // We have 60 items so we remove the oldest 
     object[] objs = new object[6];
     for (int i = 0; i < 6; i++){
          objs *= queue.Dequeue();*

}
return objs;
}
The method will remove and return your 6 oldest objects.