The following code is from a main window in a WPF application:
public MainWindow()
{
...
Storyboard myStoryboard = new Storyboard();
...
_button.Click += delegate(object sender, RoutedEventArgs args)
{
myStoryboard.Begin(_control);
};
...
}
The object myStoryboard is defined locally within MainWindow(). Yet the unnamed delegate for the button click event is able to access this object. How is this possible? When the delegate is invoked as a result of the click event, what is its runtime environment?
(C# as provided with Visual Studio 2010, .NET 4.0.)