How can I use preprocessor directives (like #define) in .NET to execute some code just on windows10? not for example on windows7?
CodePudding user response:
Pre-processor directives affect how the code is compiled; if you use a pre-processor directive here, you would need to compile it separately for Windows 10 and Windows 7, and tell people only to use the correct exe. That probably isn't what you want. Instead, perhaps simply:
if (System.OperatingSystem.IsWindowsVersionAtLeast(10))
{
// ...
}
(docs)
Note that this does not currently work for Windows 11 preview by using 11
as the input.