Hashtable
我在我的类中编写了一个简短的静态方法,以按键 (s) 的顺序迭代我拥有的一些s,string
但我遇到了一个奇怪的编译器错误。这是有问题的方法:
public static DictionaryEntry inorderHashtable(Hashtable ht) {
string[] keys = ht.Keys.Cast<string>().ToArray<string>();
Array.Sort(keys);
foreach (string key in keys) {
yield return new DictionaryEntry(key, ht[key]);
}
}
这稍后在类中使用,如下所示:
foreach(DictionaryEntry dentry in inorderHashtable(myTable)) { /* ... */ }
这是我从 VS2008 得到的错误:'ns.myclass.inorderHashtable(System.Collections.Hashtable)' cannot be an iterator block because 'System.Collections.DictionaryEntry' is not an iterator interface type
有什么办法可以解决这个错误?提前致谢。