我使用的是哪个版本的 C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19532942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which version of C# am I using
提问by Salvador Dali
I want to find out which version of C# I'm using.
If I would be using python I would do something like python -V
from the command line, or type:
我想知道我使用的是哪个版本的 C#。如果我要使用 python,我会python -V
从命令行做类似的事情,或者输入:
import sys
print sys.version
In PHP I would do something like this: phpinfo();
in java: java -version
在 PHP 中,我会做这样的事情:phpinfo();
在 Java 中:java -version
But I was not able to find how to achieve this in C#.
但是我找不到如何在 C# 中实现这一点。
This questiondoes not answer it, although the name suggests that it should.
这个问题没有回答它,尽管名称表明它应该回答。
I got that it depends on the .NET framework, but is there a programmatic way of figuring out my framework? I mean without going to the directory and checking the name of my .NET folders.
我知道它取决于 .NET 框架,但是有没有一种编程方式来确定我的框架?我的意思是不去目录并检查我的 .NET 文件夹的名称。
采纳答案by Alexei Levenkov
To get version of framework - look at version of one of main Assemblies i.e.
要获取框架版本 - 查看主要程序集之一的版本,即
Console.Write(typeof(string).Assembly.ImageRuntimeVersion);
Getting version of C# compiler is somewhat harder, but you should be able to guess version by checking what framework version is used.
获取 C# 编译器的版本有点困难,但您应该能够通过检查使用的框架版本来猜测版本。
If you are using command line compiler (csc.exe) you can check help to see version (also you'd need to know Framework version anyway:
如果您使用的是命令行编译器 (csc.exe),您可以查看帮助以查看版本(您也需要知道框架版本:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>csc /?
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
回答by Praveen
It depends upon the .NET Framework
that you use. Check Jon Skeet's answerabout Versions.
这取决于.NET Framework
你使用的。检查Jon Skeet关于版本的回答。
Here is short version of his answer.
这是他回答的简短版本。
C# 1.0released with .NET 1.0
C# 1.2(bizarrely enough); released with .NET 1.1
C# 2.0released with .NET 2.0
C# 3.0released with .NET 3.5
C# 4.0released with .NET 4
C# 5.0released with .NET 4.5
C# 6.0released with .NET 4.6
C# 7.0is released with .NET 4.6.2
C# 7.3is released with .NET 4.7.2
C# 8.0is released with NET Core 3.0
C# 1.0与.NET 1.0 一起发布
C# 1.2(很奇怪);随.NET 1.1 一起发布
C# 2.0与.NET 2.0 一起发布
C# 3.0与.NET 3.5 一起发布
C# 4.0与.NET 4 一起发布
C# 5.0与.NET 4.5 一起发布
C# 6.0与.NET 4.6 一起发布
C# 7.0与.NET 4.6.2 一起发布
C# 7.3与.NET 4.7.2 一起发布
C# 8.0与NET Core 3.0 一起发布
回答by Vinay Pratap Singh
The C# version you are using totally depends upon the .Net version you are using.
您使用的 C# 版本完全取决于您使用的 .Net 版本。
if you are using visual studio for development, you get to choose the .net framework version the c# version associated with it comes accordingly
如果您使用 Visual Studio 进行开发,您可以选择相应的 .net 框架版本与它相关的 c# 版本
These are the versions of C# known:
这些是已知的 C# 版本:
- C# 1.0released with .NET 1.0and VS2002 (January 2002)
- C# 1.2(bizarrely enough); released with .NET 1.1 and VS2003 (April 2003). First version to call
Dispose
onIEnumerator
s which implementedIDisposable
. A few other small features.- C# 2.0released with .NET 2.0and VS2005 (November 2005). Major new features: generics, anonymous methods, nullable types, iterator blocks
- C# 3.0released with .NET 3.5and VS2008 (November 2007). Major new features: lambda expressions, extension methods, expression trees, anonymous types, implicit typing (
var
), query expressions- C# 4.0released with .NET 4and VS2010 (April 2010). Major new features: late binding (
dynamic
), delegate and interface generic variance, more COM support, named arguments and optional parameters- C# 5.0released with .NET 4.5in August 2012.
- C# 1.0随.NET 1.0和 VS2002一起发布(2002 年 1 月)
- C# 1.2(很奇怪);随 .NET 1.1 和 VS2003(2003 年 4 月)一起发布。第一个版本的呼叫
Dispose
在IEnumerator
该实施小号IDisposable
。其他一些小功能。- C# 2.0随.NET 2.0和 VS2005一起发布(2005 年 11 月)。主要新特性:泛型、匿名方法、可为空类型、迭代器块
- C# 3.0随.NET 3.5和 VS2008一起发布(2007 年 11 月)。主要新特性:lambda 表达式、扩展方法、表达式树、匿名类型、隐式类型 (
var
)、查询表达式- C# 4.0随.NET 4和 VS2010一起发布(2010 年 4 月)。主要新特性:后期绑定 (
dynamic
)、委托和接口泛型变化、更多 COM 支持、命名参数和可选参数- C# 5.0于2012 年 8 月随.NET 4.5一起发布。
Refrence Jon Skeet's C# Versions Answer
回答by Siyavash Hamdi
In order to see the installed compiler version of VC#:
要查看已安装的 VC# 编译器版本:
Open Visual Studio command prompt and just type csc then press Enter.
打开 Visual Studio 命令提示符,只需键入 csc,然后按 Enter。
You will see something like following:
您将看到类似以下内容:
Microsoft (R) Visual C# Compiler version 4.0.30319.34209
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Visual C# 编译器版本 4.0.30319.34209
适用于 Microsoft (R) .NET Framework 4.5
版权所有 (C) 微软公司。版权所有。
P.S.: "CSC" stand for "C Sharp Compiler". Actually using this command you run csc.exe which is an executable file which is located in "c:\Windows\Microsoft.NET\Framework\vX.X.XXX". For more information about CSC visit http://www.file.net/process/csc.exe.html
PS:“ CSC”代表“ C Sharp Compiler”。实际上使用这个命令你运行 csc.exe,它是一个位于“c:\Windows\Microsoft.NET\Framework\vX.X.XXX”的可执行文件。有关 CSC 的更多信息,请访问http://www.file.net/process/csc.exe.html
回答by Amod Pandey
.NET version through registry
.NET 版本通过注册表
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\ explore the children and look into each version. The one with key 'Full' is the version on the system.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\ 探索孩子并查看每个版本。键为“Full”的那个是系统上的版本。
https://support.microsoft.com/en-us/kb/318785https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
https://support.microsoft.com/en-us/kb/318785 https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
.NET version through Visual Studio
通过 Visual Studio 的 .NET 版本
Help -> About Microsoft Visual Studio -> The .NET version is specified on the top right.
帮助 -> 关于 Microsoft Visual Studio -> .NET 版本在右上角指定。
As I understand at this time the Visual studio uses .NET Framework from the OS.
据我了解,此时 Visual Studio 使用操作系统中的 .NET Framework。
The target .NET Framework version of a project in Visual Studio can be modified with Project Properties -> Application -> Target Framework
Visual Studio 中项目的目标 .NET Framework 版本可以通过 Project Properties -> Application -> Target Framework 进行修改
Through the dll
通过dll
If you know the .NET Framework directory e.g. C:\Windows\Microsoft.NET\Framework64\v4.0.30319
如果您知道 .NET Framework 目录,例如 C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Open System.dll, right click -> properties -> Details tab
打开 System.dll,右键单击 -> 属性 -> 详细信息选项卡
C# version
C#版本
Help -> About Microsoft Visual Studio
帮助 -> 关于 Microsoft Visual Studio
In the installed products lists there is Visual C#. In my case Visual C# 2015
在已安装的产品列表中有 Visual C#。就我而言,Visual C# 2015
Visual Studio (Microsoft) ships C# by name Visual C#.
Visual Studio (Microsoft) 通过名称 Visual C# 提供 C#。
https://msdn.microsoft.com/en-us/library/hh156499.aspx
https://msdn.microsoft.com/en-us/library/hh156499.aspx
C# 6, Visual Studio .NET 2015 Current version, see below
C# 6, Visual Studio .NET 2015 当前版本,见下文
回答by Darth
While this isn't answering your question directly, I'm putting this here as google brought this page up first in my searches when I was looking for this info.
虽然这并不能直接回答您的问题,但我将其放在这里是因为当我在寻找此信息时,谷歌首先在我的搜索中显示了此页面。
If you're using Visual Studio, you can right clickon your project -> Properties -> Build -> AdvancedThis should list available versions as well as the one your proj is using.
如果您使用的Visual Studio,你可以右键点击在您的项目- >属性- >生成- >高级这应该列出可用的版本,以及你的凸出正在使用一个。
回答by Ankit Mori
By default following are corresponding version of C# compilers for Visual Studio:
默认情况下,以下是 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
- 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
You can also modify version please follow below steps.
您也可以修改版本,请按照以下步骤操作。
Open the project properties window:
打开项目属性窗口:
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"
回答by Roman
For Windows, you run dev at the command/ search program line and select Developer Command Prompt for VS. Then you are going to just run
对于 Windows,您在命令/搜索程序行运行 dev 并选择 Developer Command Prompt for VS。然后你就跑
csc
Now you get information similar to
现在你得到的信息类似于
Microsoft (R) Visual C# Compiler version 2.6.0.62329 (5429b35d)
Copyright (C) Microsoft Corporation. All rights reserved.
For Windows and if you start with cmd terminal
对于 Windows,如果您从 cmd 终端开始
cd C:\Windows\Microsoft.NET\Framework\
dir
Now you see all directories and files in .NET\Framework\ Please, select v... latest and go there, for example,
现在您会看到 .NET\Framework\ 中的所有目录和文件,请选择 v... latest 并转到那里,例如,
cd v4.0.30319
Run
跑
csc
You will see information about version of C# compiler, that can be something similar to
您将看到有关 C# 编译器版本的信息,这可能类似于
Microsoft (R) Visual C# Compiler version 4.7.2556.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.
回答by fortesl
From developer command prompt type
从开发人员命令提示符类型
csc -langversion:?
That will display all C# versions supported including the default:
这将显示支持的所有 C# 版本,包括默认值:
1
2
3
4
5
6
7.0 (default)
7.1
7.2
7.3 (latest)
回答by Sunil Jadhav
If you are using VS2015 then follow below steps to find out the same:
如果您使用的是 VS2015,请按照以下步骤找出相同的:
- Right click on the project.
- Click on the Propertiestab.
- From properties window select Buildoption.
- In that click on the Advancebutton.
- There you will find out the language version.
- 右键单击项目。
- 单击“属性”选项卡。
- 从属性窗口中选择构建选项。
- 在那个点击高级按钮。
- 在那里你会找到语言版本。
Below images show the steps for the same:
下图显示了相同的步骤:
Step 1:
第1步:
Step 2:
第2步: