Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void InternalsTest_VariableOutsideLoop()
- {
- var strings = new List<string> {"one", "two", "three"};
- var buttons = new List<Button>();
- var displayClass = new DisplayClass();
- for (int index = 0; index < strings.Count; index++)
- {
- displayClass.str = strings[index];
- var btn = new Button();
- btn.Click += displayClass.action;
- buttons.Add(btn);
- }
- buttons.ForEach(x => x.PerformClick());
- }
- private sealed class DisplayClass
- {
- public string str { get; set; }
- public void action(object sender, EventArgs e)
- {
- MessageBox.Show(str);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement