I run this program but it does not assign the value of or 3 to s, instead before running it gave the sintax error unassigned local variable 's'

        private void button1_Click(object sender, EventArgs e)
        {
            int i, y, s;
            i = 8;
            y = 6;
                if (i == 6)
                {
                    s = y;
                }
                else
                {
                   s = 3;
                }
                listBox1.Items.Add(s)
        }

Recommended Answers

All 3 Replies

i ve tested your code and it works, by the way put a semicolon after your last line of code altouhg i think that this is not the problem.

listBox1.Items.Add(s);

I put the semicolon forgot it when I pass to this site.

Thank you you are correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.