各位朋友:
想请教一下,在C#里面有没有相当于DELPHI的With...Do语句,例如以下语句:
ListBox3.Items.Clear();
ListBox3.Items.Add("GOOGLE图片");
ListBox3.Items.Add("GOOGLE音乐");
ListBox3.Items.Add("GOOGLE网站");在DELPHI里面可以写成:
with listBox3 do
begin
items.clear();
items.add(..);
items.add(..);
.......
end;
通过用With...do语句可以减少代码的输入量和精简代码,想请教一下,在C#里面,有没有相关的语句呢?请各位朋友赐教,谢谢!!!
想请教一下,在C#里面有没有相当于DELPHI的With...Do语句,例如以下语句:
ListBox3.Items.Clear();
ListBox3.Items.Add("GOOGLE图片");
ListBox3.Items.Add("GOOGLE音乐");
ListBox3.Items.Add("GOOGLE网站");在DELPHI里面可以写成:
with listBox3 do
begin
items.clear();
items.add(..);
items.add(..);
.......
end;
通过用With...do语句可以减少代码的输入量和精简代码,想请教一下,在C#里面,有没有相关的语句呢?请各位朋友赐教,谢谢!!!
with object do end with
foreach(string itemName in ItemNames)
{
ListBox3.Items.Add(itemName);
}
listbox1.selectindex=2;
listbox1.selectvalue="Hello";小弟只是举一个例子来说明一下问题,因为以前一直都习惯用DELPHI来作东西,所以觉得With..Do挺方便的,现在转了C#,想看看有没有类似的语句,谢谢!
{
string itemName;
int itemIndex;
string itemValue;
}
然后还是用foreach(Item i in items)可以不
你就是要遍历所添加的项 那用foreach应该是很方便啊
呵呵~~