如何通过键获取值和linq的另一个值? vbnet

时间:2017-05-27 12:00:31

标签: c# linq

Public ets As New Dictionary(Of String, info)

Public Class info

    Public Property index As Integer

    Public Property imglst_index As Integer

End Class

我希望在带有linq查询的字典中通过index =“x”和key =“y”获取imglst_index。

     For Each subKey As String In subKeys

             Dim result = exts.FirstOrDefault(Function(x) x.Key = subkey AndAlso x.Value.ext_icon_index = subkey.DefaultIcon.Index).Value.ext_imglst_index

                  if result>0 then item2.imageindex=result

                    Dim item As New ListViewItem(subKey)
                    item.ImageIndex = ImageList.Images.Count - 1
                    item.Tag = subKey
                    Items.Add(item)
                    exts.Add(subkey, New ext_info With {.ext_icon_index = subkey.DefaultIcon.Index, .ext_imglst_index = item.ImageIndex})


     Next subKey

这是我的代码。

2 个答案:

答案 0 :(得分:0)

你就是这样做的。

Dim result = ets.First(Function(x) x.Key = "y" AndAlso x.Value.index="x") _
                .Value _
                .imglst_index

答案 1 :(得分:0)

试试这个

command2