当前位置: 首页 > 知识库问答 >
问题:

使用VS 2015打开VS 2017项目时的语法错误[重复]

史默
2023-03-14

我有一个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说“字符串”是一个无效的表达式。我该如何解决这个问题?

共有1个答案

井疏珂
2023-03-14

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

string username;
if (props.TryGetValue("username", out username)) 
{
    edtUsername.Text = username; 
}
 类似资料:
  • 我的环境变量路径中的值为 C:\ProgramData\Oracle\Java\JavaPath;C:\Windows\System32;C:\Windows;C:\Windows\System32\WBEM;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\JDK1.8.0_51\bin;C:\Program Fi

  • 我不明白为什么这个delete语句会出现语法错误: 错误: Msg 156,级别15,状态1,第18行关键字“left”附近语法不正确。

  • 我的公司正在开发一个利用博世视频SDK的应用程序。我已经在我的安装项目中包含了所需的DLL文件,我相信它们在我的项目安装时正在注册,但我在运行时遇到了“未注册类”错误。。 我怀疑我的问题来自这样一个事实,即这个应用程序是在x64中编译的,并且使用BOSCH视频软件开发工具包中的64位DLL。这是有意的,我们绝对希望它以64位模式安装和运行。 确切的错误消息是“由于以下错误,为CLSID为{D12F

  • 主要内容:Eclipse 重新打开关闭的项目Eclipse 重新打开关闭的项目 要重新打开一个关闭的项目,在 Package Explorer 视图中,选择关闭的项目并单击 Project 菜单并选择 Open Project。 项目打开后,可以使用 Eclipse 用户界面编辑其内容。

  • 错误:任务“app:transformClassesWithDexForDebug”的执行失败。

  • 我正在尝试使用此查询删除具有重复的列值的行: 但这给了 查询看起来很好。我错过了什么?