我正在尝试创建一个二维数组,它以字符串形式保存注册表的根键及其子键,所以我希望数组是
string[rootkeys][subkeys]
但由于某种原因,在分配时我得到了NullReferenceException
:
你调用的对象是空的。
这是我的代码。关于我做错了什么的任何想法?
public string[][] getAllRootSubKeys(){
int i = 0;
int h = 0;
var allRoots = new List<RegistryKey> {Registry.ClassesRoot, Registry.CurrentUser, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig};
string[][] rootAndKey = null;
foreach (var root in allRoots) {
rootAndKey[i][h] = root.GetSubKeyNames()[h];
h++;
if (h == root.SubKeyCount) {
i++;
h = 0;
}
}
return rootAndKey;
}