问题描述
我已经安装了一周前发布的 Visual Studio 2017 Community,并开始探索 C# 7 的新功能.
所以我创建了一个返回两个值的简单方法:
公开课程序{公共静态无效主要(字符串[]参数){(int sum, int count) a = ReturnTwoValues();}static (int sum, int count) ReturnTwoValues() =>(1, 1);}
编译器产生错误:
<块引用>错误 CS8137 无法定义使用元组的类或成员因为编译器需要类型'System.Runtime.CompilerServices.TupleElementNamesAttribute' 不能成立.您是否缺少参考资料?
我尝试在框架中找到具有此名称的引用,但没有成功!
如果我们需要额外的东西来使用 C# 7.0 的特性,那么我们需要为每个项目都这样做是很奇怪的?!
我刚刚在
按照这些步骤,它现在可以工作了.但是,对于我们开始的每个项目都需要这样做,这真的很奇怪!希望当我们正式发布时这个问题得到解决!
I've installed Visual Studio 2017 Community that was released a week ago, and I started exploring the new features of C# 7.
So I created a simple method that returns two values:
public class Program
{
public static void Main(string[] args)
{
(int sum, int count) a = ReturnTwoValues();
}
static (int sum, int count) ReturnTwoValues() => (1, 1);
}
Compiler is generating an error:
Error CS8137 Cannot define a class or member that utilizes tuples because the compiler required type 'System.Runtime.CompilerServices.TupleElementNamesAttribute' cannot be found. Are you missing a reference?
I tried finding a reference in the framework with this name, but with no luck !
If we need additional stuff to use C# 7.0 features, then it is very weird that we need to do that for every project ?!
I Just ran through this page on Roslyn which describes the following steps to get this working:
- Start a C# project
- Add a reference to the
System.ValueTuple
package from NuGet (pre-release)
Following those steps, it is now working. But it is really very weird that we need to do that for every single project that we start! Hope this is fixed when we reach the Official release!
这篇关于无法从使用 Visual Studio 2017 和 C# 7.0 的方法返回元组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!