Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
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
Updated 13-Sep-17 6:07am
v2
Comments
Member 13408203 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

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!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900