2012-09-27 36 views
2

我相当肯定我可以在VB.NET中使用Lambda表达式执行下面的代码,但我似乎无法找到这样做的示例。 Mt试图做到这一点是徒劳的。尝试使用VB.NET Lambda代替迭代器

我只是遍历Me.Controls集合,然后做两个嵌套的If(可能是一个与AndAlso相连接的)...如果条件匹配,调用.Controls.Clear ()方法。

For Each C As Control In Me.Controls 
     If TypeOf C Is GroupBox Then 
      If C.Name.StartsWith("grpScreen") Then 
       CType(C, GroupBox).Controls.Clear() 
      End If 
     End If 
    Next 

难道有人指着我正确的方向吗?谢谢你的帮助,

克里斯

回答

2

试试这个

 Me.Controls.OfType(Of GroupBox)() _ 
     .Where(Function(c) c.Name.StartsWith("grpScreen")) _ 
     .ToList() _ 
     .ForEach(Sub(c) c.Controls.Clear()) 
+0

优雅简约 - 谢谢你 – user1701982