C# 创建一个列表<;字符串>;从哈希表键?

C# 创建一个列表<;字符串>;从哈希表键?,c#,collections,hashtable,C#,Collections,Hashtable,嘿,我怎么能做得尽可能短 谢谢:-)试试这个: System.Collections.Hashtable ht = new System.Collections.Hashtable(); List<string> list = ht.Keys.Cast<string>().ToList(); System.Collections.Hashtable ht=new System.Collections.Hashtable(); List List=ht.Keys.Cast

嘿,我怎么能做得尽可能短

谢谢:-)

试试这个:

System.Collections.Hashtable ht = new System.Collections.Hashtable();
List<string> list = ht.Keys.Cast<string>().ToList();
System.Collections.Hashtable ht=new System.Collections.Hashtable();
List List=ht.Keys.Cast().ToList();

为什么不使用
字典
而不是
哈希表
?因为我的Foo可以是通用的…仍然可能?当然;如果要在泛型类
FooHolder
中声明词典,可以在其中创建
词典。