Implementing Stack<T> in C# class

The example below shows how we can implement a generic stack class in c# that can hold upto 100 objects.

public class Stack <T>
{
  int itemposition;
  T[] data = new T[100];
  public void push(T obj)
 {
    data [itemposition++] = obj;
 }
 public T Pop()
 {
    return data [--itemposition];
 }
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.