日期:2014-05-18  浏览次数:20912 次

在C#里面有没有相当于DELPHI的With...Do语句
各位朋友:
  想请教一下,在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#里面,有没有相关的语句呢?请各位朋友赐教,谢谢!!!

------解决方案--------------------
vb 才有的
------解决方案--------------------
mark
------解决方案--------------------
没有 。
------解决方案--------------------
没有
------解决方案--------------------
刚创建了一个c#和vb的交流群!欢迎高手加入!群号:47047449
------解决方案--------------------
C#没有

不过VB有
with object do 

end with
------解决方案--------------------
c#里还真没有听说过这个
------解决方案--------------------
no
------解决方案--------------------
foreach不可以吗
C# code

ListBox3.Items.Clear(); 
foreach(string itemName in ItemNames)
{
    ListBox3.Items.Add(itemName);
}

------解决方案--------------------
struct Item
{
string itemName;
int itemIndex;
string itemValue;
}
然后还是用foreach(Item i in items)可以不
你就是要遍历所添加的项 那用foreach应该是很方便啊
------解决方案--------------------
我以前也是用delphi 好像没有这样的功能。
------解决方案--------------------
我现在还在用D。所以可以很负责任地对你说:没有