yogagrmy99
yogagrmy99

Reputation: 15

Stack in C# Form, proceed button for Push

I'm having trouble implementing stack and query into C# Form application.

My code looks like this.

namespace Program_Pajak
{
    public partial class formppn : Form
    {
        public formppn()
        {
            InitializeComponent();
        }

        private void formppn_Load(object sender, EventArgs e)//kinda confused, placing stack in which function
        {
            Stack sit = new Stack();
            Stack sht = new Stack();
            int count1 = sit.Count;
            int count2 = sht.Count;
        }

        private void button1_Click(object sender, EventArgs e) //this is proceed button for Push stack
        {
            sit.Push(item);
            si.Text = count1.ToString();
        }
    }
}

I don't know which function should I declare my stack, and how to make proceed button to push data onto my stack?

Upvotes: 0

Views: 83

Answers (1)

ironstone13
ironstone13

Reputation: 3443

As @orhtej2 pointed out in his comment, you should declare your data as member variables of the formpn class. You would also be better off using a typed generic version of stack and using readonly declaration to make it clear you're not going to re-assign the collections later:

  namespace Program_Pajak
    {
        public partial class formppn : Form
        {

           Stack sit = new Stack();
           Stack sht = new Stack();

            public formppn()
            {
                InitializeComponent();
            }

            private void label2_Click(object sender, EventArgs e)
            {

            }

            private void formppn_Load(object sender, EventArgs e)//kinda confused, placing stack in which function
            {

                int count1 = sit.Count;
                int count2 = sht.Count;
            }

            private void button1_Click(object sender, EventArgs e) //this is proceed button for Push stack
            {
                sit.Push(item);
                si.Text = count1.ToString();
            }

            private void si_Click(object sender, EventArgs e)
            {

            }
        }
    }

Upvotes: 1

Related Questions