Reputation: 43321
This code is from Programming Windows, Sixth Edition book:
using Windows.ApplicationModel.Activation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
namespace StrippedDownHello
{
public class App : Application
{
static void Main(string[] args)
{
Application.Start((p) => new App());
}
...
}
}
I cannot understand the syntax of Application.Start((p) => new App());
line. In the class documentation Start
method is defined as:
public static void Start(ApplicationInitializationCallback callback);
Please explain me how this code line with lambda expression is related to the Start
method definition.
Upvotes: 2
Views: 844
Reputation: 373
The lambda is just shortcut to write an instance of the ApplicationInitializationCallback
You can check the signature of this delegate and see that it indeed takes a parameter and return nothing.
In your example, the lambda is doing exactly this: takes a parameter p, instantiates an App and return nothing.
Without using lambda you would write it like this:
static void Main(string[] args)
{
Application.Start(new ApplicationInitializationCallback(Start));
}
private static void Start(ApplicationInitializationCallbackParams p)
{
new App();
}
Upvotes: 1