资源简介
将数据文本文件读到哈希表里存储,根据《Data Structures and Algorithms Using C#》的第十章制成
代码片段和文件信息
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace Glossary
{
public partial class Form1 : Form
{
private Hashtable glossary = new Hashtable();
public Form1()
{
InitializeComponent();
}
private void BuildGlossary(Hashtable g)
{
StreamReader inFile;
string line;
string[] words;
inFile = File.OpenText(@“A:\WPF和C#程序设计\C#\数据结构与算法\words.txt“);
char[] delimiter = new char[] { ‘‘ };
while (inFile.Peek() != -1)
{
line = inFile.ReadLine();
words = line.Split(delimiter);
g.Add(words[0] words[1]);
}
inFile.Close();
}
private void DisplayWords(Hashtable g)
{
object[] words = new object[100];
g.Keys.CopyTo(words 0);
for (int i = 0; i <= words.GetUpperBound(0); i++)
if (!(words[i] == null))
lstWords.Items.Add((words[i]));
}
private void Form1_Load(object sender EventArgs e)
{
BuildGlossary(glossary);
DisplayWords(glossary);
}
private void lstWords_SelectedIndexChanged(object sender EventArgs e)
{
object word;
word = lstWords.SelectedItem;
txtDefinition.Text = glossary[word].ToString();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2011-03-28 19:45 chapter10\Glossary\
文件 866 2011-03-28 19:45 chapter10\Glossary\Glossary.sln
文件 20992 2011-03-28 20:45 chapter10\Glossary\Glossary.suo
目录 0 2011-03-28 19:46 chapter10\Glossary\Glossary\
目录 0 2011-03-28 19:45 chapter10\Glossary\Glossary\bin\
目录 0 2011-03-28 20:11 chapter10\Glossary\Glossary\bin\Debug\
文件 9728 2011-03-28 20:32 chapter10\Glossary\Glossary\bin\Debug\Glossary.exe
文件 26112 2011-03-28 20:32 chapter10\Glossary\Glossary\bin\Debug\Glossary.pdb
文件 11600 2011-03-28 20:33 chapter10\Glossary\Glossary\bin\Debug\Glossary.vshost.exe
文件 490 2010-03-17 22:39 chapter10\Glossary\Glossary\bin\Debug\Glossary.vshost.exe.manifest
文件 1617 2011-03-28 20:32 chapter10\Glossary\Glossary\Form1.cs
文件 3746 2011-03-28 20:11 chapter10\Glossary\Glossary\Form1.Designer.cs
文件 5817 2011-03-28 20:11 chapter10\Glossary\Glossary\Form1.resx
文件 3675 2011-03-28 20:11 chapter10\Glossary\Glossary\Glossary.csproj
目录 0 2011-03-28 19:45 chapter10\Glossary\Glossary\obj\
目录 0 2011-03-28 19:45 chapter10\Glossary\Glossary\obj\x86\
目录 0 2011-03-28 20:32 chapter10\Glossary\Glossary\obj\x86\Debug\
文件 6408 2011-03-28 20:32 chapter10\Glossary\Glossary\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 296 2011-03-28 20:11 chapter10\Glossary\Glossary\obj\x86\Debug\GenerateResource.read.1.tlog
文件 694 2011-03-28 20:11 chapter10\Glossary\Glossary\obj\x86\Debug\GenerateResource.write.1.tlog
文件 1027 2011-03-28 20:33 chapter10\Glossary\Glossary\obj\x86\Debug\Glossary.csproj.FileListAbsolute.txt
文件 9728 2011-03-28 20:32 chapter10\Glossary\Glossary\obj\x86\Debug\Glossary.exe
文件 180 2011-03-28 20:11 chapter10\Glossary\Glossary\obj\x86\Debug\Glossary.Form1.resources
文件 26112 2011-03-28 20:32 chapter10\Glossary\Glossary\obj\x86\Debug\Glossary.pdb
文件 180 2011-03-28 20:11 chapter10\Glossary\Glossary\obj\x86\Debug\Glossary.Properties.Resources.resources
目录 0 2011-03-28 19:45 chapter10\Glossary\Glossary\obj\x86\Debug\TempPE\
文件 489 2011-03-28 19:45 chapter10\Glossary\Glossary\Program.cs
目录 0 2011-03-28 19:45 chapter10\Glossary\Glossary\Properties\
文件 1366 2011-03-28 19:45 chapter10\Glossary\Glossary\Properties\AssemblyInfo.cs
文件 2864 2011-03-28 19:45 chapter10\Glossary\Glossary\Properties\Resources.Designer.cs
文件 5612 2011-03-28 19:45 chapter10\Glossary\Glossary\Properties\Resources.resx
............此处省略3个文件信息
- 上一篇:c#电子时钟控件
- 下一篇:JS调用c#编写的DLL 源代码
评论
共有 条评论