it's all about semantics

G

Guest

Hi
Instead of a direct opinion on the following matter I prefer to post it as a quiz. What do you expect the code below does:

---

ListItem[] litems = new ListItem[5];
for (int i = 0; i < 5; i++)
litems = new ListItem("text"+i,"value"+i);

DropDownList ddl;
for (int j = 0; j < 3; j++)
{
ddl = new DropDownList();
ddl.Items.AddRange(litems);
//assume PlaceHolder1 exists on WebForm
PlaceHolder1.Controls.Add(ddl);
}
//Now the tricky part - set selectedIndex for 2nd dropdownlist control, let's say:
((DropDownList)PlaceHolder1.Controls[1]).SelectedIndex = 0;

---

So, what do you think is the outcome of the above code?
What do you think of the code/effect semantics in this case?

dimitris
 
S

Scott G.

I'll answer with a quiz: Do you think that "sharing" ListItems in multiple DropDownLists would do something different than set the SelectedItem for all three DropDownLists?

Scott
Hi
Instead of a direct opinion on the following matter I prefer to post it as a quiz. What do you expect the code below does:

---

ListItem[] litems = new ListItem[5];
for (int i = 0; i < 5; i++)
litems = new ListItem("text"+i,"value"+i);

DropDownList ddl;
for (int j = 0; j < 3; j++)
{
ddl = new DropDownList();
ddl.Items.AddRange(litems);
//assume PlaceHolder1 exists on WebForm
PlaceHolder1.Controls.Add(ddl);
}
//Now the tricky part - set selectedIndex for 2nd dropdownlist control, let's say:
((DropDownList)PlaceHolder1.Controls[1]).SelectedIndex = 0;

---

So, what do you think is the outcome of the above code?
What do you think of the code/effect semantics in this case?

dimitris
 
G

Guest

I think it is not a logical "sharing" practice in this case.

whoever engineered that was loco.

dimitris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,312
Latest member
Svsdvsdvs

Latest Threads

Top