【问题标题】:how to fetch DictionaryEntry object from Hashtable?如何从 Hashtable 中获取 DictionaryEntry 对象?
【发布时间】:2009-11-24 11:24:30
【问题描述】:

我知道我的 Hashtable 的 key 值, 从 key 如何获取 DictinaryEntry 的对象。

我不想迭代 Hashtable。

【问题讨论】:

    标签: c# dictionary hashtable


    【解决方案1】:

    虽然DictionaryEntry 是迭代Hashtable 时返回的类型,但Hashtable '包含'DictionaryEntrys 并不是真的。 DictionaryEntry 是一个值类型,因此没有身份。如果您想要包含给定键和匹配值的“a”DictionaryEntry,您可以自己制作一个:

    DictionaryEntry de = new DictionaryEntry(key, myHashtable[key]);
    

    【讨论】:

      【解决方案2】:

      我不知道我是否正确理解了你的问题,但你不能直接用这个吗?

      myHashtable[key]
      

      【讨论】:

        【解决方案3】:

        我建议您使用 Dictionary 而不是 Hashtable,因为它是一个类型化的 Hashtable。 用于数据检索

                 if(myHahtable.ContainsKey(key))
                    object value = myHahtable[key];
        

        【讨论】:

        • 我已经使用 BindingSource 将 Hashtable 与 ComboBox 绑定了!
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-02-20
        • 1970-01-01
        • 2017-08-07
        • 1970-01-01
        • 2016-08-23
        • 1970-01-01
        • 2010-11-17
        相关资源
        最近更新 更多