【发布时间】:2019-05-21 00:58:31
【问题描述】:
我有一个 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 说“字符串”是一个无效的表达式。我该如何解决这个问题?
【问题讨论】:
-
你的意思是这段代码在VS2017中编译成功?
-
不要使用 Visual Studio 2015。
out string username是 C# 7 功能。你不能在 VS 2015 中使用 C# 7
标签: c# visual-studio visual-studio-2015 visual-studio-2017