使用 VS 2015 打开 VS 2017 项目时出现语法错误
syntax errors when opening VS 2017 project with VS 2015
我有一个 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 表示 "string" 是无效表达式。我该如何解决这个问题?
在 out
运算符之外声明字符串变量
string username;
if (props.TryGetValue("username", out username))
{
edtUsername.Text = username;
}
我有一个 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 表示 "string" 是无效表达式。我该如何解决这个问题?
在 out
运算符之外声明字符串变量
string username;
if (props.TryGetValue("username", out username))
{
edtUsername.Text = username;
}