locked
Trouble With Arrays RRS feed

  • Question

  • User-1176977130 posted

    So I have constructed a function which, when called, is supposed to return a list of 'charges' and display it.
    I am receiving one error from this function, which reads:

    Value of type 'System.Collections.Generic.List(Of DotNetNuke.Modules.AccessorialCharges.ChargesInfo)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of DotNetNuke.Modules.AccessorialCharges.ChargesInfo)'

    I understand the error, but am unsure why I am getting it.
    I have checked over the code piece by piece a number of times, and can't find my mistake.
    Any suggestions are appreciated.
    Code to follow:

     

    1    Public Shared Function GetCharges(ByVal ModuleId As Integer) As List(Of ChargesInfo)()
    2 Dim ChargesInfolist As List(Of ChargesInfo) = New List(Of ChargesInfo)
    3 Using dr As IDataReader = DataProvider.Instance().GetCharges(ModuleId)
    4 While dr.Read
    5 Dim ChargesInfo As ChargesInfo = New ChargesInfo
    6 ChargesInfo.ChargeId = Convert.ToInt32(dr("ChargeId"))
    7 ChargesInfo.Expense = Convert.ToString(dr("Expense"))
    8 ChargesInfo.OptionType = Convert.ToString(dr("OptionType"))
    9 ChargesInfo.ViewOrder = Convert.ToInt32(ConvertNullInteger(dr("ViewOrder")))
    10 ChargesInfo.CreatedByUser = Convert.ToInt32(dr("CreatedByUser"))
    11 ChargesInfo.CreatedDate = Convert.ToDateTime(dr("CreatedDate"))
    12 ChargesInfolist.Add(ChargesInfo)
    13 End While
    14 End
    Using
    15 Return ChargesInfolist
    16 End Function
     

     

     

    Friday, January 16, 2009 12:24 PM

Answers

  • User-294030300 posted

    Hey,

    Try changing this:

    Public Shared Function GetCharges(ByVal ModuleId As Integer) As List(Of ChargesInfo)() 

    to this:

    Public Shared Function GetCharges(ByVal ModuleId As Integer) As List(Of ChargesInfo) 

    Which is missing the last () from the definition.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 16, 2009 12:37 PM

All replies

  • User-294030300 posted

    Hey,

    Try changing this:

    Public Shared Function GetCharges(ByVal ModuleId As Integer) As List(Of ChargesInfo)() 

    to this:

    Public Shared Function GetCharges(ByVal ModuleId As Integer) As List(Of ChargesInfo) 

    Which is missing the last () from the definition.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 16, 2009 12:37 PM
  • User-1176977130 posted

    Bingo.

    Thanks, man.

    Friday, January 16, 2009 12:45 PM