我如何在运行时在哈希表中添加新项(名称) [英] How I add a new items (namers) in the hashtable at run time

查看:82
本文介绍了我如何在运行时在哈希表中添加新项(名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我制作了一个包含很多名字的哈希表,所以我需要在运行时输入更多的名字或项目,我是怎么做的,就像我使用文本框和标签和按钮一样。 />
谢谢

Hello
I made a hashtable containing many names , so I need to enter more names or items at run time how do I that, by the way I use textbox and labele and button .
thank you

推荐答案

不确定你要求的是什么......哈希表有'键'和'值'顺便说一下,你不要说你的文本框是关键还是价值......



我们假设文本框是值 - 我猜是



a)您可以将标签文本设置为在此输入新条目

b)您可以将按钮的点击或点击事件设置为(例如)button_OnClicked()

c)你要将代码添加到button_OnClicked()函数'就像': -



Not exactly sure what you're asking for .... hashtables have 'keys' AND 'values' btw, you dont say wether your textbox is the key or the value ....

Let's assume that the textbox is the value - my guess is

a) you would set the label text to something like 'Type new entry here'
b) you would set the 'click' or 'clicked' event for the button to (for example) button_OnClicked()
c) you would add code to the button_OnClicked() function 'like' :-

Dim sValue as String;
sValue = textbox.Text();

// key - what is the key for the entry ??

if (! sValue.IsNullorEmpty)
{
  // given myHashTab is a previously populated hashtable
  //
  if (! myHashTab.ContainsKey(key))
  {
      myHashTab.Add(key, sValue);      // key is undefined since you dont indicate how you intent to provide a value for it 
  }
}





我怀疑那是合法的VB.Net但它在按钮处理程序中需要做的事情



I doubt thats legal VB.Net but its the sort of thing you need to do in the button handler


这篇关于我如何在运行时在哈希表中添加新项(名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆