关于linq的一个问题 [英] One Question about linq

查看:88
本文介绍了关于linq的一个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
如何使用Linq访问GroupBoxes中的嵌套对象(如TextBoxes)?
非常感谢.....

Hi...
How do I use Linq to access a nested object like TextBoxes that are in GroupBoxes?
very Thanks.....

推荐答案

这是我的工作方式:

This is how I did :

IEnumerable<control> controls = from Control control in groupBox1.Controls
                                select control;</control>



现在您可以枚举类似这样的控件:



Now you can enumerate over controls like this :

foreach(Control control in controls)
{
  //Do your operation here.

}


不要重新发布您的问题,BTW Tarun向您展示了一种将linQ与IEnumerable集合一起使用的方法.这是您问题的可接受答案.

但您介意提供更多详细信息,为什么要在这里使用linQ.塔伦答案的结果可能是相同的groupBox1.controls.要在内部搜索控件? groupBox1.controls.find("Button1", true/false);.但是您可能有特定的原因在这里使用LinQ.我只是想知道原因.很高兴知道不同的想法:)
Don''t repost your question, BTW Tarun showed you a way how to use linQ with IEnumerable collections. That is an acceptable answer for your question.

But would you mind providing some more details why you want linQ here. What the result in Tarun''s answer can be the same groupBox1.controls. To search a control inside? groupBox1.controls.find("Button1", true/false);. But you may be having specific reasons to use LinQ here. I am just interested to know the reason. Good to know different thoughts :)


这篇关于关于linq的一个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆