C#7 .NET / CLR / Visual Studio版本要求 [英] C# 7 .NET / CLR / Visual Studio version requirements

查看:126
本文介绍了C#7 .NET / CLR / Visual Studio版本要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行C#7的最低.NET框架和CLR版本要求是什么?另外,我是否需要VS 2017来编译C#7?

What are the minimum .NET framework and CLR version requirements for running C# 7? Also, do I need VS 2017 to compile C# 7?

推荐答案

您不需要定位.NET 4.6及更高版本,是不正确的。要使用元组,您需要System.ValueTuple NuGet包。就在 https://www.nuget.org/packages/System.ValueTuple/ 您会看到它说它支持4.5及更高版本,实际上,它支持4.0及更高版本。而且,如果您想发疯,则可以创建自己的 System.ValueTuple 类,该类正是该程序包所能完成的工作,它可以在.NET 3.5上运行,甚至可能更旧。对于类似于任务的类型,您还需要一个NuGet包, https:/ /www.nuget.org/packages/System.Threading.Tasks.Extensions/ 。根据其文档,该软件包还可以在.NET 4.5和更高版本上使用。

You do NOT need to target .NET 4.6 and above, that is incorrect. To use Tuples, you need the System.ValueTuple NuGet package. Right on https://www.nuget.org/packages/System.ValueTuple/ you can see it says it supports 4.5 and above, and actually, it supports 4.0 and above. And if you want to get crazy, if you create your own System.ValueTuple class that does exactly what that package does, it will work back on .NET 3.5 and probably older too. For "Task-like" types, you also need a NuGet package, https://www.nuget.org/packages/System.Threading.Tasks.Extensions/. This package also works on .NET 4.5 and newer according to its documentation.

其他C#7功能仅在.NET 2及更高版本上可用,因为它们只是语法糖。例如,我刚刚在.NET 2.0中编写了以下内容,并且正确抛出了该内容:

Other C# 7 features will just work on .NET 2 and above as they are just syntactic sugar. For example, I just wrote the following in .NET 2.0 and it correctly throws:

static void Main(string[] args)
{
    string test = null;
    string d = test ?? throw new ApplicationException("test");
}

与之类似, int.TryParse( 123, out int i); 在.NET 2.0中工作正常。

Likewise, int.TryParse("123", out int i); works just fine in .NET 2.0.

我并没有测试每个C#7功能,但是总的来说,除了Tuples(以及诸如deconstruction之类的相关功能)外,它应该可以在.NET中工作。 2.0及更高版本,因为它只是语法糖。话虽这么说,是的,您需要VS2017来编译C#7。我确定某些时候其他编译器将支持C#7,但今天不支持。

I did not test every single C#7 feature, but in general, with the exception of Tuples (and their related features like deconstruction), it should work in .NET 2.0 and above as most of it is just syntactic sugar. That being said, yes you need VS2017 to compile C#7. I'm sure at some point other compilers will support C#7 but not today.

我确认在.NET 2.0中可以使用的功能:

Features I confirmed work in .NET 2.0:


  • 二进制文字

  • 数字分隔符

  • 内联 out 参数

  • 使用 _ 舍弃参数

  • 本地函数

  • 基于类型的模式匹配 if(obj is int i) case int i:

  • 常量模式匹配如果(i为2)

  • 各种模式匹配 if(我是var j)

  • 引用返回

  • 抛出表达式

  • 表达体的getter和setters

  • 表达体的构造函数和终结器

  • Binary Literals
  • Digit Separators
  • Inline out parameters
  • Using _ to discard out parameters
  • Local functions
  • Type based pattern matching if (obj is int i) and case int i:
  • Constant pattern matching if (i is 2)
  • Var pattern matching if (i is var j)
  • Ref returns
  • Throw expressions
  • Expression bodied getters and setters
  • Expression bodied constructors and finalizers

这篇关于C#7 .NET / CLR / Visual Studio版本要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆