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) 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

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.

C# 7 .NET / CLR / Visual Studio version requirements的更多相关文章

  1. MySQL for Visual Studio Version

    MySQL for Visual Studio Version Connector/Net Version Supported Visual Studio Version Supported MySQ ...

  2. Getting Visual Studio version of a Solution file

    VS 6.0 -> 6.0 VS 2002 -> 7.0 VS 2003 -> 8.0 VS 2005 -> 9.0 VS 2008 -> 10.0 VS 2010 -& ...

  3. Visual Studio 2010初学者的调试指南:Mastering Debugging in Visual Studio 2010 - A Beginner's Guide

    Introduction In the software development life cycle, testing and defect fixing take more time than a ...

  4. visual studio 2012 has stopped working

    I had similar problem which was resolved by taking two steps : 1A. DELETE THE REGISTRY KEY : 32-bit ...

  5. Building Python 2.7.10 with Visual Studio 2010 or 2015 - Google Chrome

    您的浏览器(Chrome 33) 需要更新.该浏览器有诸多安全漏洞,无法显示本网站的所有功能. 了解如何更新浏览器 × p-nand-q.com C++  Python  Programming  L ...

  6. 如何在Visual Studio VS中定义多项目模板

    https://msdn.microsoft.com/en-us/library/ms185308.aspx Multi-project templates act as containers for ...

  7. CUDA 新版本 Visual Studio 和 CUDA 兼容性的小问题

    ▶ 升级到 Visual Studio 2017 和 CUDA 9.1 之后,直接编译以前的 CUDA C 程序出现了如下报错: 严重性 代码 说明 项目 文件 行 禁止显示状态 错误(活动) E00 ...

  8. How to check if Visual Studio 2005 SP1 is installed

    How to check if Visual Studio 2005 SP1 is installed Check the following registry key. HKEY_LOCAL_MAC ...

  9. visual studio git 忽略文件配置模板

    ## Ignore Visual Studio temporary files, build results, and## files generated by popular Visual Stud ...

随机推荐

  1. 【转】char data[0]用法总结

    @2019-07-31 struct MyData { int nLen; ]; }; 开始没有理解红色部分的内容,上网搜索下,发现用处很大,记录下来. 在结构中,data是一个数组名:但该数组没有元 ...

  2. 9. A Pythonic Object

    Thanks to the Python data model, your user-defined types can behave as naturally as the built-in typ ...

  3. Gym - 102141D 通项公式 最短路

    题目很长,但是意思就是给你n,A,B,C,D n表示有n个城市 A是飞机的重量 B是一个常数表示转机代价 C是单位燃油的价格 D是一个常数 假设一个点到另外一个点的距离为整数L 起飞前的油量为f  则 ...

  4. GDI根据位图和透明度创建蒙版

    #include <windows.h> LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l ...

  5. 【Amaple教程】4. 组件

    在Amaple单页应用中,一个页面其实存在两种模块化单位,分别是 模块 (am.Module类),它是以web单页应用跳转更新为最小单位所拆分的独立块: 组件 (am.Component类),它的定位 ...

  6. 如何低成本搭建dnslog服务器

    DNSLog,简单来说,就是通过记录对于域名的DNS请求,通过dns请求这个相对"隐蔽"的渠道,来委婉地获取到想要获得的信息. 例如,在一个针对mysql数据库的注入中,如果没有回 ...

  7. c++ 用eclipse建立一个类,并实例化并运行

    新建项目 file->new->c/c++ project 项目结构 cpc.cpp //================================================= ...

  8. mysql批量新增和批量删除

    首先推荐使用PreparedStatement的批量处理操作. Connection conn = null; PreparedStatement stmt = null; try{ Class.fo ...

  9. py操作mongodb总结

    python使用的版本 python3. python操作mongodb使用的是pymongo,安装方法: pip install pymongo 测试 PyMongo 接下来我们可以创建一个测试文件 ...

  10. DNS服务基础

    DNS服务器的功能 – 正向解析:根据注册的域名查找其对应的IP地址 – 反向解析:根据IP地址查找对应的注册域名(不常用) NS(声明DNS记录) A(正向解析记录) CNAME(解析记录别名) 安 ...