C# 7 在 VS 15 Preview 4 中工作吗?

Is C# 7 working in VS 15 Preview 4?

我尝试了一个简单的测试,但它不喜欢输出变量

作为一个简单的测试,我写了这个(也许它有一些简单的错误,但我也遇到了模式和元组的问题)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{

    public class Program
    {
        static void Main(string[] args)
        {
            Runner runner = new ConsoleApplication2.Runner();
            Point p = new ConsoleApplication2.Point();
            runner.PrintCoordinates(p);
        }
    }


    public class Point
    {
        int x = 20;
        int y = 50;
        public void GetCoordinates(out int a, out int b)
        {
            a = x;
            b = y;
        }
    }

    public class Runner
    {
        public void PrintCoordinates(Point p)
        {
            p.GetCoordinates(out int x, out int y);
            Console.WriteLine($"({x}, {y})");       // x does not exist in current context
        }
    }
}

根据this post,其中PrintCoordinates示例方法来自:

Note: In Preview 4, the scope rules are more restrictive: Out variables are scoped to the statement they are declared in. Thus, the above example will not work until a later release.

新的元组也遇到了类似的问题,尽管您似乎可以通过下载 NuGet 部分解决该问题:

Note: Tuples rely on a set of underlying types, that aren’t included in Preview 4. To make the feature work, you can easily get them via NuGet:

  • Right-click the project in the Solution Explorer and select “Manage NuGet Packages…”
  • Select the “Browse” tab, check “Include prerelease” and select “nuget.org” as the “Package source”
  • Search for “System.ValueTuple” and install it.