C#从两个文本文档中获取信息
Getting information from two text documents in C#
我正在用 C# 编写一个程序,我想将两个文本文档加载到两个字符串数组中(wordlist.txt 和 dict.txt)。
wordlist.txt 文件包含 10 行,每行一个单词,dict.txt 包含10行,每行一个句子。我想做的是,当用户在 wordlist.txt 的第 4 行输入一个单词时,程序会在 [=16] 的相应行号上显示一个句子=]dict.txt。
我怎样才能做到这一点?请帮忙!
- 使用
File.ReadAllLines
将两个文件加载到一个数组中。第一个数组将包含单词,第二个数组将包含句子。
- 获得数组后,创建一个字典(假设单词在这里是唯一的)。
- 使用用户输入作为键显示字典值。
这是执行#2 的示例。恕我直言,休息是微不足道的。
List<string> words; // Create using ReadAllLines and then call ToList.
string[] sentences; // Create in #1
Dictionary<string, string> map = words.ToDictionary(x => x, x => sentences[words.IndexOf(x)]);
我正在用 C# 编写一个程序,我想将两个文本文档加载到两个字符串数组中(wordlist.txt 和 dict.txt)。
wordlist.txt 文件包含 10 行,每行一个单词,dict.txt 包含10行,每行一个句子。我想做的是,当用户在 wordlist.txt 的第 4 行输入一个单词时,程序会在 [=16] 的相应行号上显示一个句子=]dict.txt。
我怎样才能做到这一点?请帮忙!
- 使用
File.ReadAllLines
将两个文件加载到一个数组中。第一个数组将包含单词,第二个数组将包含句子。 - 获得数组后,创建一个字典(假设单词在这里是唯一的)。
- 使用用户输入作为键显示字典值。
这是执行#2 的示例。恕我直言,休息是微不足道的。
List<string> words; // Create using ReadAllLines and then call ToList.
string[] sentences; // Create in #1
Dictionary<string, string> map = words.ToDictionary(x => x, x => sentences[words.IndexOf(x)]);