public T first() { if (internal_stack.Count == 0) { return(default(T)); } return(internal_stack.ToArray()[internal_stack.Count - 1]); }
public static String Encode(long input) { if (input < 0) { throw new ArgumentOutOfRangeException("input", input, "input cannot be negative"); } var result = new System.Collections.Generic.Stack <char>(); while (input != 0) { result.Push(CharList[(int)(input % CharList.Length)]); input /= CharList.Length; } return(new string(result.ToArray())); }
/// <devdoc> /// Click event handler for the Finish button. /// </devdoc> protected virtual void OnFinishButtonClick(object sender, System.EventArgs e) { WizardPanel currentPanel = _panelHistory.Peek(); if (currentPanel.OnNext()) { // Call OnComplete for every panel on the stack WizardPanel[] panels = _panelHistory.ToArray(); Array.Reverse(panels); foreach (WizardPanel panel in panels) { panel.OnComplete(); } DialogResult = DialogResult.OK; Close(); } }
public static void Demo() { Console.WriteLine("Stack......"); System.Collections.Generic.Stack <string> names = new System.Collections.Generic.Stack <string>(); names.Push("Andrew"); names.Push("Bobby"); names.Push("Candy"); names.Push("Dana"); names.Push("Edith"); Console.WriteLine("Default content of stack"); foreach (string name in names) { Console.WriteLine(name); } Console.WriteLine("\nPopping '{0}'", names.Pop()); Console.WriteLine("Peek at next item to display what will" + " be destacked: {0}", names.Peek()); Console.WriteLine("Now, after peek, popping '{0}'", names.Pop()); System.Collections.Generic.Stack <string> stack2 = new System.Collections.Generic.Stack <string>(names.ToArray()); Console.WriteLine("\nContents of the first copy:"); foreach (string name in stack2) { Console.WriteLine(name); } string[] array2 = new string[names.Count * 2]; names.CopyTo(array2, names.Count); System.Collections.Generic.Stack <string> stack3 = new System.Collections.Generic.Stack <string>(array2); Console.WriteLine("\nContents of the second copy, with " + "duplicates and nulls:"); foreach (string name in stack3) { Console.WriteLine(name); } Console.WriteLine("\nstack2.Contains(\"Dana\") = {0}", stack2.Contains("Dana")); Console.WriteLine("\nstack2.Clear()"); stack2.Clear(); Console.WriteLine("\nstack2.Count = {0}", stack2.Count); Console.WriteLine("End of Stack"); }
public Enumerator(System.Collections.Generic.Stack <T> backingStack) { this.values = backingStack.ToArray(); }