【发布时间】:2016-07-08 05:59:23
【问题描述】:
我正在尝试使用 .txt 文件中的字符串 [] 数组填充哈希表, 我从目录中读取了 .txt,但无法用 foreach 填充哈希表 我遇到错误 = 语法错误;期望值 希望你能指导我一点。 第一语言。
static Hashtable GetHashtable()
{
// Create and return new Hashtable.
Hashtable ht_rut = new Hashtable();
//Create a string from all the text
string rutcompleto = System.IO.File.ReadAllText(@"C:\datos rut.txt");
//create an array from the string split by ,
String[] rutArr = rutcompleto.Split(',');
//create a int key for the hashtable
int key = 1;
foreach (var item in rutArr)
{
ht_rut.Add(key,rutArr[]);
key = key + 1;
}
return ht_rut;
}
}
【问题讨论】: