Pop off array in C#
Use a List, Queue or Stack instead..
List<String>
Queue<String>
Stack<String>
Queue<T>
(first in, first out) or Stack<T>
(last in, first out) are what you're after.
Arrays in .NET are fixed length - you can't remove an element from them or indeed add elements to them. You can do this with a List<T>
but Queue<T>
and Stack<T>
are more appropriate when you want queue/stack semantics.
From MSDN:
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class MSDNSample
{
static void Main()
{
string input = "a b c d";
Stack<string> myStack = new Stack<string>(
input.Split(new string[] { " " }, StringSplitOptions.None));
// Remove the top element (will be d!)
myStack.Pop();
Queue<string> myQueue = new Queue<string>(
input.Split(new string[] { " " }, StringSplitOptions.None));
// Remove the first element (will be a!)
myQueue.Dequeue();
}
}
}
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/a924097e-3d72-439d-984a-b371cd10bcf4/