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. js之数据类型(对象类型——单体内置对象——Math)

    Math是一个内置对象,它具有数学常数和函数的属性和方法.Math对象用于执行数学任务,和其它对象不同,Math只是一个静态对象并没有Math()构造函数,实际上,Math()只是一个由js设置的对象 ...

  2. Outline 科学的上网

    outline 官网:https://getoutline.org/zh-CN/home 下载 Outline 管理器 下载 Outline 客户端 配置浏览器代理

  3. webapi 之 post参数传递

    最近在写webapi,在写post请求接口时遇到了不少的问题,在此记录下来. post请求的参数和get请求有点不一样,我们知道get请求的参数是通过url来传递的,而post请求则是通过http的请 ...

  4. 一个简单的例子学会github repository的webhook

    github的webhook是个有用的功能,允许开发人员指定一个服务器的url.当开发者对github仓库施加操作,比如提交代码,创建issue时,github网站会自动向该url指定的服务器推送事件 ...

  5. 文件的空间使用和IO统计

    数据库占用的存储空间,从高层次来看,可以查看数据库文件(数据文件,日志文件)占用的存储空间,从较细的粒度上来看,分为数据表,索引,分区占用的存储空间.监控数据库对象占用的硬盘空间,包括已分配,未分配, ...

  6. 10.自定义EL函数和自定义标签

    需要在JSP页面中进行一些常见逻辑操作(如对字符串进行操作),首先考虑是否可以用到sun公司提供的EL函数库(fn.tld)和JSTL 核心标签库 如果sun公司的EL函数库没有或者无法满足,就需要自 ...

  7. C++手动调用析构函数无效问题排查

    在学习C++的时候,都知道不要手动调用析构函数,也不要在构造函数.析构函数里调用虚函数.工作这么多年,这些冷门的知识极少用到,渐渐被繁杂的业务逻辑淹没掉. 不过,最近项目里出现了析构函数没有被正确地调 ...

  8. element之input输入搜索联想框

    1. 模板代码 <el-autocomplete :minlength="2" v-model="searchName" :fetch-suggestio ...

  9. linux基础4-压缩及其相关的命令

    一 压缩的原理以及gzip.bzip2.tar三个命令的: Linux下文件的压缩与打包 二 zip.zipinfo.unzip: zip:压缩成.zip文件 zipinfo:列出压缩文件信息

  10. Linux/Unix/Cygwin 常用命令

    以下只说明各指令的基本用法,若需详细说明,请用man去读详细的manual.[Cygwin通常没有安装 man相关的文件,所以没有man功能] 1.关于文件/目录处理的指令: 1.1 ls 这是最基本 ...