System.Collections.Generic PushFront Method C#

Hi,

Rather than to define my own, I am wondering if their is a push_front method defined somewhere in a template that I can easily use.

using a stack provides pop and push, using a queue provides enqueue and deuque using a List provides Remove and Add. I have also looked in a LinkedList and LinkedListNode. I need to use PushFront for each GUI Text written to the screen.

Particles Collided! <--Enqueue

ParticlesCollidedTwice! <--- PushFront

ParticlesCollided!

ParticlesCollidedThrice! <--PushFront newest

ParticlesCollidedTwice! <–PushFront oldest

ParticlesCollided!

Edit: Here a snippet:

//Enter this method each time we want to display a new message
public void AddNewMessage(string myMessage /*,Vector4 pos*/)
{
    GUIStyle myStyle;
    Vector4 Position;
    Color myColor = Color.red;

    Messages m = new Messages(myMessage, new Vector4(475,lowPoint,1000,2000), myColor);

    if (count < 3) 
    {
        MessageList.Add(m);
        lowPoint = lowPoint + 10;
        count++;
    }
    else
    {
        foreach (Messages ms in MessageList)
        {
             // I just went ahead and tried to progress by emulating a push front.
            if (ms.Position.y == lowPoint-myVar)
            {
                MessageList.Remove(ms);
                Messages msg = new Messages(myMessage, new Vector4(475, lowPoint-myVar,1000,2000), myColor);
                MessageList.Add(msg);
                newCount++;
                break;
            }
            if (newCount < 3) 
            {
                lowPoint = 500;
                count = 0;
            }
        }

        myVar = myVar + 10;
    }
}

public class Messages
{
    //...format the message..
    public Messages(string msg, Vector4 pos, Color txtColor/*, Font txtFont*/)
    {
        // Format the message
        newMessage = msg;
        Position = pos;
        myColor = txtColor;
    }

    public void Draw()
    {
        GUI.Label(new Rect(Position.x, Position.y, Position.z, Position.w), newMessage);                
    }
}

void OnGUI()
{       

    foreach (Messages msgs in MessageList)
    {
        msgs.Draw();
    }
}
}

Wait... do you just want to add the messages to the top instead of the bottom, so the newest one displays first? It would have been a lot easier if you had quite literally just asked "How can I insert something into the front of an array instead of the back?" You didn't have to over-complicate it by making up your own terms like "push front", that's probably why noone responded.

All you need to use is `List.Insert(int index, T item);`.

http://msdn.microsoft.com/en-us/library/sey5k5z4.aspx

You would use it like this, to insert something at the start of the array:

myList.Insert(0, myItem);