Advertisement
H4x0

Sample: Object Intilizer & Using Delegates

Jan 8th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. /*
  2.  * Variable Msg's scope is within this method
  3.  */
  4. string Msg = "Clicked";
  5.  
  6. /*
  7.  * Use Object Intilizer
  8.  */
  9. Button BTN_1 = new Button()
  10. {
  11.     Text = "Click Me",
  12.     Size = new Size(100, 20),
  13.     Location = new Point(5, 5)
  14. };
  15.  
  16. /*
  17.  * Define what the button click event does within this method
  18.  * This way you can use variables with limited scope
  19.  */
  20. BTN_1.Click += delegate
  21. {
  22.     MessageBox.Show(Msg);
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement