Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:50:39+00:00 2026-06-11T10:50:39+00:00

In vb.net If I have HashTable , key is integer and the value is

  • 0

In vb.net If I have HashTable,key is integer and the value is a list of integers, how to append integers to the value of a given key,
I have tried it but each time I found the integer last added only, (the list only has the last item added).

Here is my code , where dt is DataTable object

Dim dt = report.getEvaluationReportByObjectiveGroupId(29)
Dim data As New Hashtable()
Dim dataEntry As DictionaryEntry

Dim res As String
For Each row As DataRow In dt.Rows
    Dim strYear = row.Item("Year")
    Dim strData = row.Item("EmpCount")


    If data.ContainsKey(strYear) Then
        Dim newCountArr As List(Of Int32) = DirectCast(data(strYear), List(Of Int32))
        '   newCountArr.AddRange(data(strYear))
        newCountArr.Add(strData)
        '  data.Remove(strYear)
        ' data.Add(strYear, newCountArr)
    Else
        Dim countArr As New List(Of Integer)
        countArr.Add(strData)
        data.Add(strYear, countArr)
    End If

    ' data.Add(strYear, strData)
Next row
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:50:40+00:00Added an answer on June 11, 2026 at 10:50 am

    I would suggest to use the strongly typed Dictionary(Of Int32, List(Of Int32)) instead, it works similar. But anyway, here’s the HashTable approach:

    Dim table = New Hashtable
    Dim list = New List(Of Int32)
    For i = 1 To 999
        list.Add(i)
    Next
    table.Add(1, list)
    
    ' somewhere else you want to read the list for a given key (here 1) '
    Dim list1 As List(Of Int32) = DirectCast(table(1), List(Of Int32))
    list.Add(1000) ' add another integer to the end of the list '
    ' note: you don't need to add the list to the HashTable again '
    

    Edit: Since you’ve posted your code, here’s the corrected:

    For Each row As DataRow In dt.Rows
        Dim strYear = row.Field(Of Int32)("Year")
        Dim strData = row.Field(Of Int32)("EmpCount")
        Dim list As List(Of Int32)
    
        If data.ContainsKey(strYear) Then
            list = DirectCast(data(strYear), List(Of Int32))
        Else
            list = New List(Of Int32)
            data.Add(strYear, list)
        End If
        list.Add(strData)
    Next row
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does .NET have anything similar to Perl arrays, which are indexed numerically but automatically
.NET we have primitive datatypes like int and value types like struct. And also
I try to run ELMAH with my ASP.NET MVC 2 project but have some
I'm converting Visual Basic.Net code to C# in my project. But I have some
I have checked the whole site and googled on the net but was unable
Does .NET have some type of built in function that allows filtering on Gridviews?
Does .Net have any built in constants for common numbers like million, billion etc?
Does .net have the equivilent of Delphi's QuotedStr function. This replaces all quotes with
.Net assemblies have pdb files for debugging. The PDB file points to the exact
I have .NET application that is hosted on IIS 6.1 It is impossible to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.