Placing and removing element on array trough object

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-07T14:39:58Z Indexed on 2010/04/07 14:43 UTC
Read the original article Hit count: 147

Filed under:

Hello,

Lets assume i have 2 methods 1 that places a element on the array and one that removes it.

    const int Max = 10;
    int[] table= new int[Max];

I would like to call it up like this:

s1.Place(5);  // 5 0 0 0 0 0 0 0 0 0 0
s1.Place(9);  // 5 9 0 0 0 0 0 0 0 0 0
s1.Remove(9); // 5 0 0 0 0 0 0 0 0 0 0

I would only like to use : using system for this.

The result i get right now when i run the program is s1 = "nameofprogram" "name of class object"
Normally i should get 0 0 0 0 0 0 0 0 0 0 to begin with.

Any ideas how i can exactly add or remove those elements on the array?

        public void Place(int g)
    {
        if (top == Max)
        {
            throw new Exception("Stack overflow...");
        }
        else
        {
            table[top] = g;
            top++;
        }

....

Best Regards.

© Stack Overflow or respective owner

Related posts about c#