| |

VerySource

 Forgot password?
 Register
Search
View: 830|Reply: 3

Does Hashtable make assignments like this?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-9 21:20:02
| Show all posts |Read mode
// The following method does not work in practical applications, and cannot be assigned to Hashtable.
Hashtable ht = new Hashtable ();
for (int i = 0; i <5; i ++)
{
   // I want the hash table key value to be dynamic, so I used the variable i
   ht.Add (i.toString (), i);
}

I don't know what's wrong, is there any way to solve it!
Is there any other way besides the following ways?
ht.Add (0,0);
ht.Add (1,1);
ht.Add (2,2);
ht.Add (3,3);
.....
Reply

Use magic Report

1

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Invalid IP Address

Post time: 2020-1-11 08:18:02
| Show all posts
Hashtable ht = new Hashtable ();
ht [i.toString ()] = i;
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-11 09:09:01
| Show all posts
No, it doesn't seem to be a problem
Reply

Use magic Report

1

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-11 13:00:02
| Show all posts
There is no problem with your method. Is it that you can't get the value? If you write it like that, it should be written as the value.
ht ["1"].
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list