我已经写了一段代码,我绝对认为它没有写出正确的方式。 我的方法必须根据安装在我的机器上的Adobe版本返回一个字符串。需要帮助改进现有的代码段
private string GetRegistryKeyPathForX()
{
string sPath = string.Empty;
RegistryKey adobe = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Adobe");
if (adobe != null)
{
RegistryKey acroRead = adobe.OpenSubKey("Adobe Acrobat");
if (acroRead != null)
{
string[] acroReadVersions = acroRead.GetSubKeyNames();
//The following version(s) of Acrobat Reader are installed
foreach (string versionNumber in acroReadVersions)
{
switch(versionNumber)
{
case "6.0": sPath = "Software\\Adobe\\Acrobat Reader";
return sPath; //Improve here
break;
case "7.0":
sPath = "";
return sPath; //Improve here
break;
case "8.0":
sPath = "";
return sPath; //Improve here
break;
case "9.0" :
sPath = "Software\\Adobe\\Acrobat Reader";
return sPath; //Improve here
break;
default: sPath = "ERR_KEY";
break;
}
}
}
}
return sPath;
}
有没有一种办法,这样我可以一次性返回字符串,而不是在所有情况下语句中给它的?
谢谢...这工作,但我不允许使用Linq查询:(在2.0框架中。 – 2010-12-16 12:29:23
@这个我很公平,更新我的答案与“纯2.0”代码以及。:) – 2010-12-16 12:45:06
你是男人 !! – 2010-12-16 14:47:44