我正在尝试将 .txt 文件中的值导入我的dictionary
. .txt 文件的格式如下:
唐老鸭, 2010-04-03
依此类推……每行都有 1 个这样的条目。当我尝试将拆分字符串添加到dictionary
.
我正在尝试这样: scoreList.Add(values[0], values[1]);
但它说名称在上下文中不存在。我希望有人能指出我正确的方向......
谢谢!
private void Form1_Load(object sender, EventArgs e)
{
Dictionary<string, DateTime> scoreList = new Dictionary<string, DateTime>();
string path = @"list.txt";
var query = (from line in File.ReadAllLines(path)
let values = line.Split(',')
select new { Key = values[0], Value = values[1] });
foreach (KeyValuePair<string, DateTime> pair in scoreList)
{
scoreList.Add(values[0], values[1]);
}
textBox1.Text = scoreList.Keys.ToString();
}