Created
October 23, 2009 21:29
-
-
Save atheken/217202 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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