本帖最后由 9881008杜鹏 于 2011-12-16 00:52 编辑
namespace 翻译
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Dictionary<string, string> dic = new Dictionary<string, string>();
private void Form1_Load(object sender, EventArgs e)
{
string [] str = File.ReadAllLines("英汉词典.txt", Encoding.Default);
foreach (string line in str)
{
string[] lines = line.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);//移除所有空白字符
if (line.Length == 2)
{
if (!dic.ContainsKey(lines[0]))//如果key中有相同的值将不添加进key
{
dic.Add(lines[0], lines[1]);//该处使用两个参数初始化(key,value)
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
if (dic.ContainsKey(txtkey.Text))
{
textBox2.Text = dic[txtkey.Text];
}
else
{
MessageBox.Show("sorry,没找到您要查的词!");
return;
}
}
}
}
问题:在textbox2.text中不显示键值对的value 。 |
|