Difference between C# compiler version and language version

前端 未结 4 1522
天命终不由人
天命终不由人 2020-12-24 08:08

There was time I thought that the Framework version and the C# version are the same things, so once you install the next Framework version on the computer, you should use it

4条回答
  •  感情败类
    2020-12-24 08:49

    To indicate to Visual Studio which language version to use there's a compiler option called /langversion
    You can find more about it here.
    It can be set programmatically too, as stated here.
    The compiler can compile in different versions of the language, the language version is not directly related to that of the framework, but often to use a language feature there's a minimum framework for which it can work.
    Just few minutes ago I have compiled in VS 2015 a dll which uses the string interpolation of c# 6.0

    var version = 4;
    var output = $"{version}";
    

    and has the framework 4.0 as target. It compiles and works fine. This post explains versions entanglement, but only for older c# versions.

提交回复
热议问题