473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to pass array of values to the hash table in c#

If we have to pass values to the hash table from file then what is the way???pls tel me...we have to use array,but then how we divide this array to key and value filds.pls tel me m new to this technology...........
Aug 17 '07 #1
2 2392
nateraaaa
663 Expert 512MB
If we have to pass values to the hash table from file then what is the way???pls tel me...we have to use array,but then how we divide this array to key and value filds.pls tel me m new to this technology...........
You will need to create a loop that will iterate through your array and add a new key value pair to your hashtable.

The key will be the item in the array. (The key of your hashtable has to be unique).
You can assign a value of whatever you want to each item in your hashtable. (You can have a duplicate value for a different key).

Here is a quick example.

Expand|Select|Wrap|Line Numbers
  1. Hashtable hash = new Hashtable();
  2. int count = 0;
  3. string output = "";
  4. string[] _array = {"Text1", "Text2", "Text3"};
  5.  
  6. foreach(string _text in _array)
  7. {
  8. hash.Add(_text, "Value" + count++);
  9. }
  10.  
  11. IDictionaryEnumerator _enumerator = hash.GetEnumerator();
  12. while(_enumerator.MoveNext())
  13. {
  14. output += _enumerator.Key + " ";
  15. output += _enumerator.Value + "\n";
  16. }
  17.  
  18. Response.Write(output);
This should help.

Nathan
Aug 17 '07 #2
Plater
7,872 Expert 4TB
Seems pretty similar to your other post.

http://www.thescripts.com/forum/thread694246.html
Aug 17 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: T.S.Negi | last post by:
Dear Techies, I making one stored procedure, which does some operation based on an interface hash (#) table ---- name #mydata. This stored has two section of code (seperated by parameter value...
31
by: Alexis Nikichine | last post by:
Hello, It is common knowledge that arrays can be used as hashtables: var color = ; color = 0xFF0000; color = 0x0000FF;
26
by: JGH | last post by:
How can I check if a key is defined in an associative array? var users = new array(); users = "Joe Blow"; users = "John Doe"; users = "Jane Doe"; function isUser (userID) { if (?????)
5
by: R. Rajesh Jeba Anbiah | last post by:
I could see that it is possible to have hash array using objects like var hash = {"a" : "1", "b" : "2"}; Couldn't still findout how to declare hash array in Array. var arr = new Array("a" : "1",...
47
by: VK | last post by:
Or why I just did myArray = "Computers" but myArray.length is showing 0. What a hey? There is a new trend to treat arrays and hashes as they were some variations of the same thing. But they...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
8
by: J. B. Moreno | last post by:
What's the best (i.e. fastest) way to find out if an array contains a given value? Other than looping, the only way I know to do it is to use an associative array/hash instead.... Is there a...
9
by: IamIan | last post by:
I'm using an array to store map features (name, lat, lon, caption, etc), from which the user can then select an individual feature. The problem is that when thousands of features are stored in the...
3
by: giloosh | last post by:
can i pass a hash as a function parameter. ive seen it been used before but i can't figure out how to do it. i would like to call a function like this for example ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.