In-line Pre-Processor Directives in C#

April 29, 2016

While following this article on how to add in-app purchases to UWP apps, I came across a little quirk of conditional compilation directives. Initially, I started structuring my code like this:

Windows.ApplicationModel.Store.PurchaseResults result;
    result = await Windows.ApplicationModel.Store.CurrentAppSimulator.RequestProductPurchaseAsync(Description);
    result = await Windows.ApplicationModel.Store.CurrentApp.RequestProductPurchaseAsync(Description);

But then I realised, that the code can be split over multiple lines such that the compile directive can sit halfway through the command; like this:

Windows.ApplicationModel.Store.PurchaseResults result = await

The MSDN documentation of this can be found here.

Profile picture

A blog about one man's journey through code… and some pictures of the Peak District

© Paul Michaels 2022