55. Stack class in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace stack_class
{
class Program
{
static void Main(string[] args)
{
Stack s1 = new Stack();
s1.Push(5);
s1.Push(15);
s1.Push(25);
s1.Push(35);
s1.Push(45);
foreach (int val in s1)
{
Console.WriteLine(val);
}
s1.Pop();
s1.Pop();
Console.WriteLine("==== After POP operation ====");
foreach (int val in s1)
{
Console.WriteLine(val);
}
Console.WriteLine("Peek Operation : " + s1.Peek());
Console.WriteLine("Contains Operation : " + s1.Contains(25));
Console.WriteLine("Total Element : " + s1.Count);
Console.WriteLine("==== After Clone of Stack ====");
Stack s2 = (Stack)s1.Clone();
foreach (int val in s1)
{
Console.WriteLine(val);
}
Console.WriteLine("==== After Object into Array ====");
object[] arr1;
arr1 = s1.ToArray();
foreach (object val in arr1)
{
Console.WriteLine(val);
}
Console.WriteLine("==== After Clear Method ====");
s1.Clear();
Console.WriteLine("Total Element : " + s1.Count);
Console.Read();
}
}
}
Comments
Post a Comment