2016-03-31 26 views
-3

我还没有在C#中工作过一段时间,但我正在查看别人的代码,而他们在vaca上。一切运行良好本地,我仍然得到这个“无法到达的代码检测”错误,并且我想知道这个语句是否设置正确。如果/ endif在C#中检测到“无法到达的代码”

下面是一段代码:

private string GetRedirectUriForCurrentConfiguration() { 

#if (DEBUG || DebugDev) 
     return "http://localhost:1855/"; 
#endif 
     return "http://172.16.40.39:1855"; 
    } 

    private string GetAuthorityForCurrentConfiguration() { 

#if (DebugDev) 
     return "http://172.16.40.32:44301/identity"; 
#endif 
#if (DEBUG) 
     return "https://localhost:44301/identity"; 
#endif 

我得到4号线的“无法访问”的消息,在return "http://172.16.40.39:1855";

我可能失去了一些东西超明显,但我只需要一些帮助看到它:/

在此先感谢!

+5

它不是一个错误这是一个警告。 **如果**你处于调试模式'return“http://172.16.40.39:1855”;'将无法访问,这就是警告的内容。 –

+0

在功能区栏上的Visual Studio中,您可以通过下拉菜单切换构建配置。 – aguertin

回答

3

只需添加一个#else预处理器指令代码:

private string GetRedirectUriForCurrentConfiguration() { 

#if (DEBUG || DebugDev) 
    return "http://localhost:1855/"; 
#else 
    return "http://172.16.40.39:1855"; 
#endif 
} 
+3

没错。在调试模式下,OP的代码相当于2个连续的'return'语句。有了这个,无论调试模式如何,它都是一个或另一个。因此,没有警告。 –

相关问题