public void UsingAction() { var textBox = new TextBox(); textBox.TextChanged += delegate(string s) { Console.WriteLine("Text Changed: " + s); }; textBox.SetText("Hello World!"); }
public void NoMemoryLeak() { var textBox = new TextBox(); Action<string> onTextChanged = delegate(string s) { Console.WriteLine("Text Changed: " + s); }; textBox.TextChanged += onTextChanged; textBox.SetText("Hello World!"); textBox.TextChanged -= onTextChanged; }