Click here to Skip to main content
13,596,673 members
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 5:18am
Updated 13-Sep-17 6:07am
v2
Comments
13-Sep-17 11:19am
   
it's little Urgent, any comment will be accepted. Thanks!
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.
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'

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 | Cookies | Terms of Service
Web01-2016 | 2.8.180621.3 | Last Updated 13 Sep 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

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