TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Deena eliz
NA
50
19.8k
changing hashtable value of particular key in c#
May 8 2015 3:22 AM
HI everyone,,
This is my code for add data into hashtable and modify particulat value..
Hashtable HT = new Hashtable();
int val = 0;
private void button1_Click(object sender, EventArgs e)
{
HT.Add(textBox1.Text,val);
HT.Add(textBox2.Text, val);
HT.Add(textBox3.Text, val);
HT.Add(textBox4.Text, val);
foreach (DictionaryEntry de in HT)
{
MessageBox.Show(de.Key + " " + de.Value);
}
}
i have added some values in hashtable as above code.. if i add same data again it should check with all the keys. if it is exist, value should be increase.. i did this some wat as below code
int val1 = 0;
if (HT.ContainsKey(textBox5.Text))
{
HT[textBox5.Text] = ++val;
}
else if (!HT.ContainsKey(textBox5.Text))
{
HT.Add(textBox5.Text,val1);
}
foreach (DictionaryEntry de in HT)
{
MessageBox.Show(de.Key + " " + de.Value);
}
but am getting wrong answer.. if i add same key, the value should increase as 1.. then i add another same key the value should come as also 1(0+1) but its showing 2 (1+1)
please anyone clear my doubt..
thanks in advance..
Attachment:
globaldata.rar
Reply
Answers (
0
)
Query
Regex on 08-05-2015