简体   繁体   English

如何从具有键值对的属性列表集合中获取键列表

[英]How to get a list of keys from a collection of list of properties with key value pairs

I have a collection of list of properties with key value pairs as follow screenshot in visual studio. 我有一些具有键值对的属性列表,如visual studio中的屏幕截图所示。

在此处输入图片说明

UPDATE: 更新:

I have the following screenshot if i expend the value(0) on the above screenshot. 如果我在上面的屏幕截图上花费了值(0),则我有以下屏幕截图。

在此处输入图片说明

How can I get a list (List (of string) may be?) with Key values from that? 如何从中获取具有键值的列表(列表(可能是字符串)?)?

For example, the new list will contain, {Id, Class Name, Forename, Surname, Dob}. 例如,新列表将包含{Id,类名,前称,姓氏,Dob}。 No need to filter anything. 无需过滤任何内容。

Many Thanks 非常感谢

If your list is a collection of KeyValue pairs then can you not just iterate this collection and build up a new list of strings representing the Key 如果您的列表是KeyValue对的集合,那么您不仅可以迭代该集合并建立一个新的表示Key的字符串列表

   Dim l2 As New List(Of String)
    For Each kvp As KeyValuePair(Of String, String) In res(0)
        l2.Add(kvp.Key)
    Next

Here is an example. 这是一个例子。 In this example, the key for each KeyValuePair is a String, but it might not always be, so there is an explicit .ToString() just in case the keys are another type. 在此示例中,每个KeyValuePair的键都是一个String,但可能并不总是这样,因此,以防万一这些键是另一种类型,因此存在一个显式的.ToString()。

Dim myList As New List(Of KeyValuePair(Of String, Object))
' add stuff to myList here

Dim keyList as List(Of String)
For Each item In myList
    keyList.Add(item.Key.ToString())
Next item

EDIT: Try this: 编辑:试试这个:

' add stuff to myList here

Dim keyList as List(Of String)
For Each entry in res
    For Each item In entry._values
            keyList.Add(item.Key.ToString())
    Next item
Next Entry

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM