user1339913
user1339913

Reputation: 1027

Value of type '1-dimensional array of System.Collections.Hashtable' cannot be converted to 'System.Collections.Hashtable

I am using a hastable but when i add a value to it i get an error

Value of type '1-dimensional array of System.Collections.Hashtable' cannot be converted to 'System.Collections.Hashtable'

Am i missing missing really basic.

  Public Shared Function LstItemsAsHT() As Hashtable()

        Dim htStudents As Hashtable = New Hashtable()

        Try
            Using dbcontext As New Entities
                Dim result = From l In dbcontext.students
                             Where l.Pass = False
                              Select l

                For Each student In result.ToList()
                    htReceipt.Add(student.Id, student.Type)

                Next
            End Using

        Catch ex As Exception

        End Try

        Return htStudents 

    End Function

Upvotes: 0

Views: 282

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460340

Your method returns a HashTable() instead of a single HashTable. Change it to:

Public Shared Function LstItemsAsHT() As Hashtable

Apart form that, why do you still use a Hashtable at all if you can use a strong typed Dictionary(Of Int32, String)? Also, the result.ToList() is not needed. You can enumerate the sequence immediately without creating a new list first.

Upvotes: 1

Related Questions