我有一個文本文件,我需要將所有偶數行放到Dictionary Key中,並將所有偶數行放到Dictionary Value中。什麼是我的問題的最佳解決方案?將txt文件轉換爲字典<string,string>
int count_lines = 1;
Dictionary<string, string> stroka = new Dictionary<string, string>();
foreach (string line in ReadLineFromFile(readFile))
{
if (count_lines % 2 == 0)
{
stroka.Add Value
}
else
{
stroka.Add Key
}
count_lines++;
}
什麼是鍵值對應關係?行號'2n-1'是關鍵,'2n'是值? – Andrei