level 4
yydgys2007
楼主
public struct data
{
public int[] version;
public string[] pathh;
}
private data GetPath(string p)
{
data d = new data();
RegistryKey hkcu = Registry.CurrentUser;
RegistryKey software = hkcu.OpenSubKey("SOFTWARE");
RegistryKey gstar = software.OpenSubKey("123");
RegistryKey soft = gstar.OpenSubKey(p);
string[] middle = soft.GetSubKeyNames();
for (int i = 0; i <= middle.Length; i++)
{
d.version[i] = int.Parse(middle[i]);
}
for (int i = 0; i <= soft.SubKeyCount; i++)
{
RegistryKey zhcn = soft.OpenSubKey("zh_CN");
d.pathh[i] = zhcn.GetValue("location").ToString();
}
soft.Close();
gstar.Close();
software.Close();
hkcu.Close();
return d;
}
调试时在“d.version[i] = int.Parse(middle[i]);”处报错,提示“Object reference not set to an instance of an object.”
查了报错信息,说是因为没有实例化,可是我middle还有d都实例化了呀?
2023年09月04日 01点09分
1
{
public int[] version;
public string[] pathh;
}
private data GetPath(string p)
{
data d = new data();
RegistryKey hkcu = Registry.CurrentUser;
RegistryKey software = hkcu.OpenSubKey("SOFTWARE");
RegistryKey gstar = software.OpenSubKey("123");
RegistryKey soft = gstar.OpenSubKey(p);
string[] middle = soft.GetSubKeyNames();
for (int i = 0; i <= middle.Length; i++)
{
d.version[i] = int.Parse(middle[i]);
}
for (int i = 0; i <= soft.SubKeyCount; i++)
{
RegistryKey zhcn = soft.OpenSubKey("zh_CN");
d.pathh[i] = zhcn.GetValue("location").ToString();
}
soft.Close();
gstar.Close();
software.Close();
hkcu.Close();
return d;
}
调试时在“d.version[i] = int.Parse(middle[i]);”处报错,提示“Object reference not set to an instance of an object.”
查了报错信息,说是因为没有实例化,可是我middle还有d都实例化了呀?