我用的是哪个版本的C#

which version of C# am I using

我的问题似乎很简单:我想知道我使用的是哪种版本的C。如果我要使用python,我将从命令行执行类似于python -V的操作,或者键入

1
2
import sys
print sys.version

在PHP中,我会做这样的事情:在Java中使用EDOCX1 1:EDCOX1×2

但我没能在C中找到实现这一点的方法。

我对C完全陌生,所以请不要打得太厉害。有什么让我惊讶的是,我不能在上面找到这个答案,所以我认为我在找东西的时候遗漏了什么或是不好。顺便说一句,这个问题没有回答,尽管名字表明它应该回答。

谢谢你的回答。现在我知道它依赖于.NET框架,但是有没有一种程序化的方法来计算我的框架?(不必转到目录并检查.NET文件夹的名称)


这取决于你使用的.NET Framework。查看乔恩·斯基特关于版本的答案。

这是他的答案的简短版本。

C# 1.0 released with .NET 1.0

C# 1.2 (bizarrely enough); released
with .NET 1.1

C# 2.0 released with .NET 2.0

C# 3.0 released with .NET 3.5

C# 4.0 released with .NET 4

C# 5.0 released with .NET 4.5

C# 6.0 released with .NET 4.6

C# 7.0 is released with .NET 4.6.2

C# 7.3 is released with .NET 4.7.2


虽然这并不能直接回答你的问题,但我把它放在这里,因为谷歌在我搜索这个信息时把这个页面放在了第一位。

如果使用的是Visual Studio,则可以右键单击项目,转到"项目属性",然后转到"生成"选项卡上的"高级"查看项目使用的版本。这应该列出可用的版本以及您的项目正在使用的版本。

enter image description here


要获取框架版本,请查看一个主要程序集的版本,即

1
 Console.Write(typeof(string).Assembly.ImageRuntimeVersion);

获取C编译器的版本有些困难,但是您应该能够通过检查使用的框架版本来猜测版本。

如果您使用的是命令行编译器(csc.exe),您可以查看帮助以查看版本(此外,您还需要了解框架版本:

1
2
C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc /?
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1


您使用的C版本完全取决于您使用的.NET版本。

如果使用Visual Studio进行开发,则可以选择.NET框架版本与之相关联的C版本相应地出现

这些是已知的C版本:

  • C# 1.0 released with .NET 1.0 and VS2002 (January 2002)
  • C# 1.2 (bizarrely enough); released with .NET 1.1 and VS2003 (April 2003). First version to call Dispose on IEnumerators which implemented IDisposable. A few other small features.
  • C# 2.0 released with .NET 2.0 and VS2005 (November 2005). Major new features: generics, anonymous methods, nullable types, iterator blocks
  • C# 3.0 released with .NET 3.5 and VS2008 (November 2007). Major new features: lambda expressions, extension methods, expression trees, anonymous types, implicit typing (var), query expressions
  • C# 4.0 released with .NET 4 and VS2010 (April 2010). Major new features: late binding (dynamic), delegate and interface generic variance, more COM support, named arguments and optional parameters
  • C# 5.0 released with .NET 4.5 in August 2012.

参考乔恩·斯基特的C版答案


通过注册表的.NET版本

hkey_local_machinesoftwaremicrosoftet framework setupdp浏览子版本并查看每个版本。键为"full"的是系统上的版本。

https://support.microsoft.com/en-us/kb/318785https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx

通过Visual Studio的.NET版本

帮助->关于Microsoft Visual Studio->右上角指定了.NET版本。

据我目前所知,Visual Studio使用操作系统中的.NET框架。

可以使用项目属性->应用程序->目标框架修改Visual Studio中项目的目标.NET框架版本。

通过动态链接库

如果您知道.NET框架目录例如c:windowsmicrosoft.netframework64v4.0.30319

打开system.dll,右键单击->属性->详细信息选项卡

C版本

帮助->关于Microsoft Visual Studio

在已安装的产品列表中有Visual C。在我的例子中,Visual C 2015

Visual Studio(Microsoft)按名称"Visual C"提供C。

https://msdn.microsoft.com/en-us/library/hh156499.aspx

C 6,Visual Studio.NET 2015当前版本,见下文


默认情况下,以下是针对Visual Studio的C编译器的相应版本:

  • Visual Studio 2015:C 6.0
  • Visual Studio 2013:C_5.0
  • Visual Studio 2012:C_5.0
  • Visual Studio 2010:C 4.0
  • Visual Studio 2008:C_3.0
  • Visual Studio 2005:C 2.0
  • Visual Studio.NET 2003:C_1.2
  • Visual Studio.NET 2002:c_1.0
  • 您也可以修改版本,请按以下步骤操作。

    打开"项目属性"窗口:

    1
    2
    3
    4
    5
    6
    step 1. Right click on the Project Name
    step 2. Select"Properties" (last option in menu)
    step 3. Select"Build" from left hand side options and scroll till down
    step 4. click on"Advance" button.
    step 5. It will open a popup and there you will get"Language Version" dropdown
    step 6. Select desired version of C# and Click"OK"


    为了查看已安装的编译器版本的vc:

    打开Visual Studio命令提示,键入csc,然后按Enter键。

    您将看到如下内容:

    Microsoft (R) Visual C# Compiler version 4.0.30319.34209

    for Microsoft (R) .NET Framework 4.5

    Copyright (C) Microsoft Corporation. All rights reserved.

    P.S.:"CSC"代表"C夏普编译器"。实际上,使用此命令可以运行csc.exe,它是位于"c:windowsmicrosoft.netframeworkvx.x.x x x"中的可执行文件。有关CSC的更多信息,请访问http://www.file.net/process/csc.exe.html。


    从开发人员命令提示类型

    csc -langversion:?

    它将显示所有支持的C版本,包括默认版本:一二三四五六7(默认)七点一七点二7.3(最新)


    对于Windows,您可以在命令/搜索程序行运行dev,并选择developer命令提示符for vs。然后您将只运行

    1
    csc

    现在你得到的信息类似于

    1
    2
    Microsoft (R) Visual C# Compiler version 2.6.0.62329 (5429b35d)
    Copyright (C) Microsoft Corporation. All rights reserved.

    对于Windows,如果从命令终端开始

    1
    2
    cd C:\Windows\Microsoft.NET\Framework\
    dir

    现在,您可以在.NETFrameworkPlease中看到所有目录和文件,请选择v…最新的,然后去那里,例如,

    1
    cd v4.0.30319

    1
    csc

    您将看到有关C编译器版本的信息,它可以类似于

    1
    2
    3
    Microsoft (R) Visual C# Compiler version 4.7.2556.0
    for C# 5
    Copyright (C) Microsoft Corporation. All rights reserved.