C# 使用VS 2015打开VS 2017项目时出现语法错误

C# 使用VS 2015打开VS 2017项目时出现语法错误,c#,visual-studio,visual-studio-2015,visual-studio-2017,C#,Visual Studio,Visual Studio 2015,Visual Studio 2017,我有一个Visual Studio 2017项目,想用Visual Studio 2015打开它 在我的C#代码中,我使用这种方法 public static bool TryGetValue(this CustomProperties props, string key, out string value) { try { CustomProperty prop = props[key]; valu

我有一个Visual Studio 2017项目,想用Visual Studio 2015打开它

在我的C#代码中,我使用这种方法

    public static bool TryGetValue(this CustomProperties props, string key, out string value)
    {
        try
        {
            CustomProperty prop = props[key];
            value = prop.Value;
            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            value = string.Empty;
            return false;
        }
    }
从集合中获取值。在构建项目时,我得到了无效的表达式术语

当我使用这行代码时

        if (props.TryGetValue("username", out string username)) // string is an invalid expression
        {
            edtUsername.Text = username; // this is unknown because the expression above throws errors
        }

Visual Studio 2015表示“字符串”是无效的表达式。如何修复此问题?

out
运算符之外声明字符串变量

string username;
if (props.TryGetValue("username", out username)) 
{
    edtUsername.Text = username; 
}

out
运算符之外声明字符串变量

string username;
if (props.TryGetValue("username", out username)) 
{
    edtUsername.Text = username; 
}

您的意思是此代码在VS2017中编译成功?不要使用Visual Studio 2015<代码>输出字符串用户名是C#7的一项功能。你不能在VS 2015中使用C#7你是说这段代码在VS2017中编译成功?不要使用Visual Studio 2015<代码>输出字符串用户名是C#7的一项功能。你不能在VS 2015中使用C#7这会还原为C#6,它不会使VS 2015与C#7一起工作这会还原为C#6,它不会使VS 2015与C#7一起工作