Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by h8crew · Jul 15, 2013 at 04:52 PM · valuekeyhashtable

Getting a key value from a hashtable?

Hey guys,

I've got some data in a hashtable(int, array) and I need to be able to loop through all the keys and get it's integer value as it's dynamic and not known.

Basically I'm pulling data from a mysql database through a WWW to a .php script, parsing the returned string into an array and using the unique row ID from the database as the key. I need to be able to loop through all the keys and put them into another array as the appropriate integers.

When I try something like this:

 var keys = new Array();
 
 for (i in myHashTable) {
     keys.push(i);
 }

I get an array full of these "System.Collections.DictionaryEntry" and not the integer (key) I'm looking for.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by perchik · Jul 15, 2013 at 05:00 PM

How is your hashtable created? If you're using C# you can access myHashTable.Keys which does exactly what you want.

 foreach(int key in myHashtable.Keys){
     Debug.Log("key:" + key + " value: "+myHashTable[key]);
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image h8crew · Jul 15, 2013 at 06:06 PM 0
Share

Sorry I should have mentioned that, it's using Javascript and I'm using this:

 var split = unparsed.Split(","[0]);
     
     for (i in split) {
         var attributes = i.Split("|"[0]);
         
         if (attributes[0] != "") {
             myHashTable.Add(parseInt(attributes[0]),attributes);
         }
     }
avatar image h8crew · Jul 15, 2013 at 06:34 PM 0
Share

I've also tried this with no luck:

 var keys = new Array();
 for(var k in myHashTable) keys.push(k);
                 
 for (i in keys) print(myHashTable[i][1]);

I get: "NullReferenceException: Object reference not set to an instance of an object"

avatar image h8crew · Jul 15, 2013 at 08:47 PM 0
Share

Ended up just moving everything to C# dictionaries.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dictionary wont give me value with correct key 1 Answer

How to call value by key when key is an object? 1 Answer

How to get the key from Array value 1 Answer

hashtable key or value index? 2 Answers

Default Null Value for Key Not Found in Dictionary? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges