C# 使用条件指令为变量赋值

C# 使用条件指令为变量赋值,c#,C#,我想将JSON文件的名称分配给变量: string environment = #if DEBUG "appsettings.Development.json"; #else "appsettings.json"; 错误为:}expected如果您缺少,则显示此错误;如果您的问题中缺少,则显示#endif: 您是否需要#endif?您是否有#endif?要了解更多信息,如果您确实有一个#endif,那么请包含更多的代码,因为只要有一个#endif,片段就可以了 string e

我想将JSON文件的名称分配给变量:

string environment =
#if DEBUG
    "appsettings.Development.json";
#else
    "appsettings.json";

错误为:}expected

如果您缺少,则显示此错误;如果您的问题中缺少,则显示
#endif

您是否需要#endif?您是否有#endif?要了解更多信息,如果您确实有一个#endif,那么请包含更多的代码,因为只要有一个#endif,片段就可以了
string environment =
#if DEBUG
    "appsettings.Development.json";
#else
    "appsettings.json";
#endif