为什么下面的代码会引发编译错误[] cannot be applied to object.
(德文粗略翻译)?如何访问对象数组作为C#中的Hashvalue
Hashtable entrys = new Hashtable();
string keyPath = "HKEY_CURRENT_USER\\Software\\Test";
string entryName = "testName";
entrys.Add(entryName, new object[]{256, RegistryValueKind.DWord}); // seems to work
foreach(DictionaryEntry entry in entrys)
{
Registry.SetValue(keyPath,
(string)entry.Key,
entry.Value[0], // error here
entry.Value[1]); // and here
}
我预计entry.Value
是对象的数组,但显然编译器认为它只是一个对象。这里有什么问题?
检查此为Registry.SetValue的正确用法-https://msdn.microsoft.com/en-us/library/3dwk5axy(V = vs.110).ASPX –
使用'字典<字符串,对象[]>'而不是'Hashtable'。哈希表不是强类型的 –
您需要施放它。 – kevintjuh93