hashtable auto populate from string

I have the following string

4,9,6,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

I wish to put into a hash table where 1,2,3,4 etc is the first column of table and the values 4, 9, 6, 7 etc are in the 2nd column
can some one help me with the c# code
websssAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelCommented:
I'm not really sure how this can be used, and also not sure I properly understand the requirements, but you may try the following code as an example. I use Dictionary instead of a hashtable:

        private void button1_Click(object sender, EventArgs e)
        {
            string valuesStr = "4,9,6,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0";
            string[] values = valuesStr.Split(',');

            int counter = 0;
            Dictionary<int, string> hashTable = new Dictionary<int, string>();

            foreach (string s in values)
            {
                counter++;
                hashTable.Add(counter, s);
            }

            // Check the result:
            foreach( int i in hashTable.Keys)
            {
                System.Diagnostics.Debug.WriteLine(i + " - " + hashTable[i]);

            }
            
        }

Open in new window



The result printed:

1 - 4
2 - 9
3 - 6
4 - 7
5 - 0
6 - 0
7 - 0
8 - 0
9 - 0
10 - 0
11 - 0
12 - 0
13 - 0
14 - 0
15 - 0
16 - 0
17 - 0
18 - 0
19 - 0
20 - 0
21 - 0
22 - 0
23 - 0
24 - 0
25 - 0
26 - 0
27 - 0
28 - 0
29 - 0
30 - 0
31 - 0
32 - 0

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.