C# 7 .NET / CLR / Visual Studio version requirements
C# 7 .NET / CLR / Visual Studio version requirements
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.
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");
}
Likewise, int.TryParse("123", out int i);
works just fine in .NET 2.0.
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.
Features I confirmed work in .NET 2.0:
- Binary Literals
- Digit Separators
- Inline
out
parameters - Using
_
to discard out parameters - Local functions
- Type based pattern matching
if (obj is int i)
andcase 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
To use the full power of C# 7 out of the box (without referencing NuGet packages and so on) you need VS 2017 and .NET 4.7 as the Target Framework.
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2015-08-05 C#中的异常处理
2015-08-05 AppDomain
2015-08-05 接口方法执行时的查找顺序
2015-08-05 log4net使用总结
2014-08-05 使用CLR Profiler查看C#运行程序的内存占用情况