并非所有的代码路径返回值 - 在哪里? [英] Not all code paths return a value - where?
本文介绍了并非所有的代码路径返回值 - 在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的C#代码。至于原因,我不会进入,这是本地化的要求的方式。
我的问题是,我不能为我的生活搞清楚什么路径没有返回一个值。有在下面的代码中没有其他错误:
ResourceManager的ResMain =新的ResourceManager(TorrentSched.Main的typeof(主) 。部件);
///<总结>返回基于当前的UI文化℃的本地化字符串; /总结>
公共字符串str(字符串名称)
{
布尔StringNotFound = FALSE;
开关(Thread.CurrentThread.CurrentUICulture.ToString())
{
案EN-GB:
开关(名称)
{
案MinimizeToTray:回归关闭程序它最小化到托盘要完全退出程序,在任务栏中右键单击该图标,然后选择退出。
默认:StringNotFound = TRUE;打破;
}
中断;
默认:
StringNotFound = TRUE;
中断;
}
如果(StringNotFound)
{
StringNotFound = FALSE;
开关(名称)
{
案APPNAME」:返回ResMain.GetString($ this.Text);
案MinimizeToTray:回归关闭程序它最小化到托盘要完全退出程序,在任务栏中右键单击该图标,然后选择退出。
案ReallyExit1:回归?你真的要退出;
案ReallyExit2:回归!山洪将不会检查并下载,直到你再次启动程序;
默认:回归字符串未找到!
}
}
}
解决方案
什么是如果块的目的是什么?据一个我可以看到,如果交换机下面的代码被执行, StringNotFound
永远是真正
所以如果 - 块是没有必要的,但它很可能混淆代码分析
I have the following C# code. For reasons I won't go into, this is the required way of localising.
My problem is, I cannot for the life of me figure out what path is not returning a value. There are no other errors in the below code:
ResourceManager ResMain = new ResourceManager("TorrentSched.Main", typeof(Main).Assembly);
/// <summary>Returns a localised string based on the Current UI Culture</summary>
public string Str(string Name)
{
Boolean StringNotFound = false;
switch(Thread.CurrentThread.CurrentUICulture.ToString())
{
case "en-GB":
switch(Name)
{
case "MinimizeToTray": return "Closing the program minimises it to the tray. To fully quit the program, right-click the icon in your tray and choose Exit.";
default: StringNotFound = true; break;
}
break;
default:
StringNotFound = true;
break;
}
if(StringNotFound)
{
StringNotFound = false;
switch(Name)
{
case "AppName": return ResMain.GetString("$this.Text");
case "MinimizeToTray": return "Closing the program minimizes it to the tray. To fully quit the program, right-click the icon in your tray and choose Exit.";
case "ReallyExit1": return "Do you really want to exit?";
case "ReallyExit2": return "Torrents will not be checked and downloaded until you launch the program again!";
default: return "String not found!";
}
}
}
解决方案
What is the purpose of the if-block? As far a I can see, if code below the switch is executed, StringNotFound
will always be true
so the if-block is not necessary, but it may very well confuse the code analysis.
这篇关于并非所有的代码路径返回值 - 在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文