# VBForums CodeBank > CodeBank - C# >  Tiny custom Stack example.

## BenJones

Hi was reading one of my old C++ and found a stack example anyway I desided to convert it to C# i know C# already has one, but this is just incase you wanted to design your own, I updated the c++ example to work with strings and you can set a custom size, ok here is the code for the class called cStack.cs



```
namespace cMyStack
{
    class cStack
    {
        private static int _size;
        private static string[] _stack;
        private static int _pos;

        public cStack(int size)
        {
            //New size
            _size = size;
            //Resize string array
            _stack = new string[size];
            _pos = 0;
        }

        public void Push(string item)
        {
            _pos++;

            if (_pos == _size)
            {
                return;
            }
            else
            {
                try
                {
                    //Push on item
                    _stack[_pos] = item;
                }
                catch { }
            }
        }

        public string Pop()
        {
            if (_pos == _size)
            {
                return "";
            }
            else
            {
                try
                {
                    _pos--;
                    //Pop off item
                    return _stack[_pos + 1];
                }
                catch
                {
                    return "";
                }
            }
        }
    }
}
```

and here is the example I made it is a console one but you can use what you like. here is the code.



```
using System;
using cMyStack;

namespace MyStack.Example
{
    class Program
    {
        static void Main(string[] args)
        {
            cStack TheStack = new cStack(50);

            TheStack.Push(" 2008");
            TheStack.Push("C#");
            TheStack.Push("Visual ");
            TheStack.Push("Microsoft ");

            Console.Write(TheStack.Pop());
            Console.Write(TheStack.Pop());
            Console.Write(TheStack.Pop());
            Console.Write(TheStack.Pop());
            //Return Microsoft Visual C# 2008

            Console.ReadKey();
        }
    }
}
```

Hope you may find some use for it.

----------

