我有以下的C#代碼。由於我不會介入的原因,這是本地化的必要方式。並非所有的代碼路徑都返回一個值 - 在哪裏?
我的問題是,我不能爲我的生活找出什麼路徑沒有返回一個值。在下面的代碼中沒有其他錯誤:
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!";
}
}
}
呈現的功能**不完整**。我猜,代碼的底部存在問題。 – Tigran
@Tigran我錯過了一個'}' - 編輯。 –
if-block的用途是什麼?就我所知,如果執行下面的代碼,'StringNotFound'將始終爲真,因此if-block不是必需的,但它可能會混淆代碼分析。 –