Click here to Skip to main content
13,351,443 members (45,424 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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?
Posted 13-Sep-17 6:18am
Updated 13-Sep-17 7:07am
CPallini418.2K
v2
Comments
Member 13408203 13-Sep-17 11:19am
   
it's little Urgent, any comment will be accepted. Thanks!
Kevin Marois 13-Sep-17 11:23am
   
It's looping through all the controls on the container represented by the 'this' keyword and subscribing their 'Click' events to something called 'ClickCounter'
Richard MacCutchan 13-Sep-17 11:36am
   
No, it's not at all urgent. And you could easily have found the answer for yourself in the documentation.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.180111.1 | Last Updated 13 Sep 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100