M
Meya-awe
Hi, i am new to C#. I am using some code similar to the one below. I am
declaring an ArrayList in one case block but the compiler complains
about it already being used in the previous case block. Is this normal
in C#? Assume that i follow this and in the first case block, i allocate
the memory using the "ArrayList mylist=new ArrayList()", and in the
second block, i just use the variable mylist like
"mylist.Add(something)". Now if the switch statement executes the second
case block first, that would case a violation, wouldn't it?
private void button1_Click(object sender, EventArgs e)
{
switch (button1.Text)
{
case "button1":
ArrayList mylist = new ArrayList();
mylist.Add(button1.Text);
button1.Text = "button2";
break;
case "button2":
ArrayList mylist = new ArrayList();
mylist.Add(button1.Text);
button1.Text = "button1";
break;
default:
break;
}
}
BRAMOIN
declaring an ArrayList in one case block but the compiler complains
about it already being used in the previous case block. Is this normal
in C#? Assume that i follow this and in the first case block, i allocate
the memory using the "ArrayList mylist=new ArrayList()", and in the
second block, i just use the variable mylist like
"mylist.Add(something)". Now if the switch statement executes the second
case block first, that would case a violation, wouldn't it?
private void button1_Click(object sender, EventArgs e)
{
switch (button1.Text)
{
case "button1":
ArrayList mylist = new ArrayList();
mylist.Add(button1.Text);
button1.Text = "button2";
break;
case "button2":
ArrayList mylist = new ArrayList();
mylist.Add(button1.Text);
button1.Text = "button1";
break;
default:
break;
}
}
BRAMOIN