How to handle events
Submit.Click += new EventHandler(Submit_Click); … void Submit_Click(object sender, EventArgs e) { // Handle the click }
In 2.0, anonymous delegates come in handy when event handlers are short enough.
Submit.Click += delegate (object sender, EventArgs evt) { // Handle the click };
is the same is
Submit.Click += delegate { // Handle the click };
But I slapped myself on the forehead when I saw this "shorthand" syntax, which is equivalent to the first example:
Submit.Click += Submit_Click; … void Submit_Click(object sender, EventArgs e) { // Handle the click }
--
Regards,
Munish Kalra
http://kalraonaspnet.blogspot.com
http://munishmca.co.nr
No comments:
Post a Comment