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

  • SEARCH
  • Home
  • 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 8637375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:27:53+00:00 2026-06-12T10:27:53+00:00

I am trying to store and get some values from Hashtable. when i getting

  • 0

I am trying to store and get some values from Hashtable. when i getting the value by passing key to that hashtable it return an null. But that has table having that passed value as key.

I am adding the Hashtable key and value using some string variables.

EDIT:
Here is my code.

Hashtable hashtbl = new Hashtable();
string[,] ValueArray =new string[3,2];
 ValueArray[0,0]="key1";
 ValueArray[0,1]="value1";
 ValueArray[1,0]="key2";
 ValueArray[1,1]="value2";
 ValueArray[2,0]="key3";
 ValueArray[2,1]="value3";

 for(int i=0;i<ValueArray.GetUpperBound(0);i++)
 {
     string mykey=ValueArray[i,0];
     string myval=ValueArray[i,1];
 if (hashtbl.ContainsKey(mykey)==false)
     {
   hashtbl.Add(mykey,myval);
     }
   }

After that i am trying to get those values like

string newVal =hashtbl[mykey].ToString();

its throws an null exception.

  • 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-12T10:27:54+00:00Added an answer on June 12, 2026 at 10:27 am

    There are few possibilities:

    • you have already inserted null under the mykey before and now you are getting it back since if statement returns true
    • myval is null and your code works flawlessly
    • mykey is of type which has a very strange implementation of GetHashCode

    The first 2 options are not actually possible, as hashtbl[mykey].ToString() would throw NullObjectReference. I would also assume that this is not the real code as I can’t think of a scenario where x.ToString() would return null, unless you forgot to mention that myval is of your custom type which overrides it in a strange way.

    Therefore, I would assume the latter: myval is your type which overrides ToString in a way that it returns null.

    EDIT:
    after showing your code and clarifying that the last line doesn’t return null but instead throws, it looks like the second scenario is happening. If you run your code through debugger, you will see that you are inserting null values for each entry where key index is > 2. Therefore, hashtable returns null.

    This snippet is suspicious: ValueArray.GetUpperBound(0) - 1. Try removing ‘-1’.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to delete certain key/value pairs from a hash, but I get
I am trying to store values in array using JavaScript, but I get strange
I'm trying to get some information from ebay api and store it in database
I'm trying to use ASIFormDataRequest for iphone to get some values from my mysql
Am trying to get some order information from XML file and trying to store
I'm trying to get the lower store from a 2010 Exchange server, and the
I am trying to get the value from the radio boxes/button with php. The
I'm trying to get some values off a DB and then putting those values
I'm trying to select and get values from customer objects. What I want to
I'm trying to read some numbers (double) from a file and store them in

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.