How does a C # program detect that it is compiled under a C # version that does not contain support for the language functions used in this program?
The C # compiler will reject the program and produce some error message when faced with the capabilities of a language that it does not support. This does not concern the problem that the program is compiled with an too old version of the C # compiler or a C # compiler that does not support the required version of C #
Ideally, it would be as simple as
#if CS_VERSION < 3 #error CSharp 3 or later is required #end
, # , MSBuild, / MSBuild.
? "" , , , "" : " โโ, , , ..."
, , , , - " ". , . , . , - . , , ( , , ).
, . , generics (detects 2.0), (3.0) (4.0)
; script. , :
โ โ โ :
( csc /langversion)
csc /langversion
, - , - . , ; ... test .
:
int[] arr1 = { 1, 2, 3, 4, 5 }; string[] arr2 = Array.ConvertAll(arr1, delegate (int i) {return i.ToString();});
This works in .NET 3.5 / ISO-2 (pseudo C # 2.0), but does not work in .NET 2.0 (correct C # 2.0).
Simple: the compiler will fail and give you an error if it cannot compile the code.
Perhaps you can read the supportedRuntime element:
You can then determine the desired directive based on the supported runtime using CSharpProjectConfigurationProperties3.DefineConstants .
You must create a macro in VS to use it.