Is it possible to determine if the current version of C # 6 or higher complies with the preprocessor directive, so at compile time?
I want to do something like this:
var myVar = ...;
string name;
#if VERSION_6_OR_MORE
name = nameof(myVar);
#else
name = "myVar";
#endif
I am using Visual Studio 2015 and C # 6, so I can use nameof(). Someone who wants to compile this code may use an older version, where nameof()not.
I want to use the preprocessor directive, so I can save it nameof()in C # 6, but someone who does not use this version can also compile it.
source
share