C#: how to write in-line code in new Event Handler Declaration

person Jason Huangfolder_openC#, Codelocal_offer, , , access_time July 2, 2015

Normally, you need to declare a new Event Handler and give this new event handler a name, then write the function inside the new event handler function to complete the code.

However, you can skip that by writing in-line code inside a declaration of new event handler.

            copyToolStripMenuItem.Name = "copyToolStripMenuItem";
            copyToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
            copyToolStripMenuItem.Text = "C&opy";
            copyToolStripMenuItem.Click += (sender, e) //copy the registry key value with new context menu item copy
                => {
                        if (myLSV.SelectedItems.Count > 0)
                            string tag = myLSV.SelectedItems[0].Tag.ToString();

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>