【发布时间】:2013-06-28 19:21:41
【问题描述】:
我正在尝试创建一个二维数组,它以字符串形式保存注册表的根键及其子键,所以我希望数组是
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;
}
【问题讨论】:
标签: c# arrays list multidimensional-array registry