【问题标题】:How to add a dictionary object to an IEnumerable如何将字典对象添加到 IEnumerable
【发布时间】:2012-11-21 05:06:31
【问题描述】:

我目前正在尝试将字典(字符串,字符串)添加到 Ienumerable(字典(字符串,字符串))

看起来很简单,但我找不到答案...如果您需要更好的解释,这是我的代码

Dim actualList As IEnumerable(Of Dictionary(Of String, String))

Dim addRows As New Dictionary(Of String, String)
        addRows.Add("LinkTitle", "Ultimate Test Item")

我想在这里,我会尝试将 addrows 放入actualList,但我在这样做时遇到了麻烦......

'this sends our custom dictionary to sharepoint
        Dim updateOutput = ListServiceUtility.UpdateListItems(Test_Sharepointsite_url, myCred, Test_List_Name, Nothing, addRows.AsEnumerable, 1)

【问题讨论】:

  • 你遇到了什么麻烦?

标签: asp.net vb.net list ienumerable


【解决方案1】:

IEnumerable 没有您正在寻找的 .Add 功能,请尝试使用 List 代替:

   Dim actualList As New List(Of Dictionary(Of String, String))

    Dim addRows As New Dictionary(Of String, String)
    addRows.Add("LinkTitle", "Ultimate Test Item")

    Dim addRows2 As New Dictionary(Of String, String)
    addRows2.Add("LinkTitle2", "Ultimate Test Item2")

    actualList.Add(addRows)
    actualList.Add(addRows2)

延伸阅读:What's the difference between IEnumerable and Array, IList and List?

【讨论】:

  • 我只是想在这里为您提供额外的道具,以便在您的示例中使用我的变量名称和测试数据来了解如何使用列表。让一切变得更容易理解。
  • @Lenigod 没有问题,如果您需要任何额外帮助,请在此处给我留言。我帮助很多 SO 用户学习新事物,这就是我喜欢在这里发帖的原因。
猜你喜欢
  • 2014-12-16
  • 1970-01-01
  • 2017-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-27
  • 1970-01-01
相关资源
最近更新 更多