Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net Visual Studio Visual Basic:访问词典集合_Vb.net_Collections_Dictionary - Fatal编程技术网

Vb.net Visual Studio Visual Basic:访问词典集合

Vb.net Visual Studio Visual Basic:访问词典集合,vb.net,collections,dictionary,Vb.net,Collections,Dictionary,我在表单的OnLoad事件子类中预定义了几个字典(带有KeyPairValue元素)。然后,我将每个字典添加到在方法外部定义的集合中,以便在表单的子例程之间访问。到目前为止还不错 我想使用这个对象创建字符串数组,用作几个不同组合框的数据源。为了做到这一点,我想检索我以前分配给这个集合中字典元素的键名。我希望通过循环遍历集合中特定字典的元素并检索键名来实现这一点。但是,我无法准确地找出如何检索keyname。以下是我正在尝试的: Collection.Item(“Dictionary1”)(cou

我在表单的OnLoad事件子类中预定义了几个字典(带有KeyPairValue元素)。然后,我将每个字典添加到在方法外部定义的集合中,以便在表单的子例程之间访问。到目前为止还不错

我想使用这个对象创建字符串数组,用作几个不同组合框的数据源。为了做到这一点,我想检索我以前分配给这个集合中字典元素的键名。我希望通过循环遍历集合中特定字典的元素并检索键名来实现这一点。但是,我无法准确地找出如何检索keyname。以下是我正在尝试的:

Collection.Item(“Dictionary1”)(counter.Key

我的目标是,有一个字典集(“Dictionary1”、“Dictionar2”等),我可以按名字查找。一旦选择了字典,我想循环遍历KeyValuePairs并检索keyName。但是,我还想将每个keyname添加为字符串数组的成员,以便可以将该字符串数组指定为comboBox的数据源

请让我知道如何在不为…创建外部计数器的情况下执行此操作。。循环


谢谢你

你应该能够按照以下思路做一些事情:

    Dim cValues As New System.Collections.Generic.Dictionary(Of String, Integer)
    Dim cKeys As New System.Collections.Generic.List(Of String)

    For Each sKey As String In cValues.Keys
        cKeys.Add(sKey)
    Next
试试这个

Dim dict As Dictionary(Of String, Integer) = Collection.Item("Dictionary1")
Dim myArray As String()
Dim list As New List(Of String)

  For Each aKey As String In dict.Keys
        list.Add(aKey)
  Next

myArray = list.ToArray()

您应该能够执行以下操作:

  Dim DictCol As New List(Of Dictionary(Of T, T)) 'this is collection of Dictionaries as a list

  Dim Keyes As New List(Of T) 'will store keys in here

  For Each dict In DictCol

    For Each pair In dict

       Keyes.Add(pair.Key)

    Next

  Next

这段代码的问题在于它不能识别每个键属于哪个字典。但是,如果在数组列表中保留键,其中每个元素都有键和字典名称,则可以解决该问题。

可以通过字典的键属性访问键。