这个怎么运作?代码如下 [英] How it works? Code written below

查看:59
本文介绍了这个怎么运作?代码如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foreach (Control c in this.Controls)
{
  c.Click += ClickCounter;
}





我的尝试:



请帮助我理解这段代码,而不是理解它正在做什么?



What I have tried:

Please help me to understand this code, not understanding what it's doing exactly?

推荐答案

这是一个基本的 foreach 循环:Controls集合中的每个对象将依次进入变量 c ,并且将使用该值执行循环体。在循环中,集合中的当前Control实例将在其Click事件中添加 ClickCounter 处理程序。



你应该能够自己解决这个问题:如果你不能,你需要在课堂上多加注意!
It's a basic foreach loop: each object in the Controls collection will "go into" the variable c in turn and the loop body will be executed with that value. Inside your loop the current Control instance from the collection will have the ClickCounter handler added to its Click event.

You should be able to work that out for yourself: if you can't you need to pay more attention in class!


这篇关于这个怎么运作?代码如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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