Skip to content

Instantly share code, notes, and snippets.

@atheken
Created October 23, 2009 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atheken/217202 to your computer and use it in GitHub Desktop.
Save atheken/217202 to your computer and use it in GitHub Desktop.
public static class ArrayUtils
{
public static void Push<T>(this T[] arr, T newItem)
{
arr = (new T[] { newItem }).Concat(arr).ToArray();
}
public static T Pop<T>(this T[] arr, T newItem)
{
T retval = default(T);
if (arr.Length > 0)
{
retval = arr[0];
arr = arr.Skip(1).ToArray();
}
return retval;
}
}
class Program
{
static void Main(string[] args)
{
int[] arr = {1};
arr.Push(1);
arr.Push(2);
foreach (var a in arr)
{
Console.WriteLine(a);
}
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment