【问题标题】:Embedded statement cannot be a declaration .Net 2.0 vs 4.0嵌入式语句不能是声明.Net 2.0 vs 4.0
【发布时间】:2013-05-15 07:10:22
【问题描述】:

我的代码中有以下声明,这些声明在 .net 框架 2.0 中运行良好,最近我将项目升级到框架 4.0,我收到构建错误提示

“嵌入语句不能是声明”

知道这里有什么问题吗?

const int sNoPrompt = 0x1;
const int sUseFileName = 0x2;
const Int32 sEmbedFonts = 0x10;
const int MultilingualSupport = 0x80;

【问题讨论】:

标签: c# declaration


【解决方案1】:

我想通了,声明正上方有一个没有大括号的 IF 语句。导致错误的原因。我刚刚删除了 IF,因为在我的情况下没有必要。现在它工作正常。

【讨论】:

    【解决方案2】:

    代码在框架 4.0 中运行良好,可能是您在代码的其他行中遇到问题。

    【讨论】:

      【解决方案3】:

      我使用以下代码之前运行良好。

      if (output == "Success")
         terminate();
      
      Configuration config = 
            ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
      var setting = config.AppSettings.Settings["PATH"];
      

      由于需求变化,我注释掉了函数调用 terminate()

      if (output == "Success")
         //terminate();
      
      Configuration config = 
            ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
      var setting = config.AppSettings.Settings["PATH"];
      

      这会在配置变量声明行中抛出错误Embedded statement cannot be a declaration或labeled statement。并且在设置变量声明行中抛出另一个错误Use of unassigned local variable 'config'

      由于 terminate() 被注释,它尝试将下一条语句作为 if 条件块。

      解决办法是注释掉full if条件块。

      //if (output == "Success")
         //terminate();
      
      Configuration config = 
            ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
      var setting = config.AppSettings.Settings["PATH"];
      

      另一种解决方案是根据需要放置花括号。

      if (output == "Success")
      {
         //terminate();
      
          Configuration config = 
             ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
          var setting = config.AppSettings.Settings["PATH"];
      }
      

      【讨论】:

        猜你喜欢
        • 2018-04-18
        • 1970-01-01
        • 1970-01-01
        • 2016-11-17
        • 2023-04-07
        • 1970-01-01
        • 2023-03-22
        • 2013-10-24
        相关资源
        最近更新 更多