locked
how to declare Array of dictionary in VB.net RRS feed

  • Question

  • User-310369200 posted

     Dim AttributeValuePairs() As Dictionary(Of String, String) = New Dictionary(Of String, String)

     

    byt this i mean   AttributeValuePairs is a Array of dictionaries

    the above syntax is wrong.

    :(


     

     

    Monday, January 14, 2008 6:44 AM

Answers

  • User-2116278700 posted

    Hi,

    try this

    Dim AttributeValuePairs() As Dictionary(Of String, String)

    Thanks and best regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 7:12 AM
  • User-2116278700 posted

    Or you can try this as well

    Dim AttributeValuePairs(2) As Dictionary(Of String, String)

    AttributeValuePairs(1) = New Dictionary(Of String, String)

    AttributeValuePairs(2) = New Dictionary(Of String, String)

    Thanks and best regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 7:15 AM
  • User397347636 posted

    Dim AttributeValuePairs() As Dictionary(Of String, String) = New Dictionary(Of String, String)() {}

    You need the array specifier (empty parentheses) in the initializer part, but since VB confuses these with the parentheses on a constructor call, you need the curly brackets.  VB then knows that it must be dealing with an array.  This is a weakness of the VB compiler - you shouldn't have to specify the curly brackets in obvious cases like this where the compiler should be able to determine that the 'New' is initializing the array and not calling some other constructor.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 10:03 AM

All replies

  • User-2116278700 posted

    Hi,

    try this

    Dim AttributeValuePairs() As Dictionary(Of String, String)

    Thanks and best regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 7:12 AM
  • User-2116278700 posted

    Or you can try this as well

    Dim AttributeValuePairs(2) As Dictionary(Of String, String)

    AttributeValuePairs(1) = New Dictionary(Of String, String)

    AttributeValuePairs(2) = New Dictionary(Of String, String)

    Thanks and best regards,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 7:15 AM
  • User397347636 posted

    Dim AttributeValuePairs() As Dictionary(Of String, String) = New Dictionary(Of String, String)() {}

    You need the array specifier (empty parentheses) in the initializer part, but since VB confuses these with the parentheses on a constructor call, you need the curly brackets.  VB then knows that it must be dealing with an array.  This is a weakness of the VB compiler - you shouldn't have to specify the curly brackets in obvious cases like this where the compiler should be able to determine that the 'New' is initializing the array and not calling some other constructor.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 14, 2008 10:03 AM
  • User-310369200 posted

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

    Tuesday, January 27, 2009 4:31 AM