這段代碼的工作原理,但我不明白其背後的原因(它只是程序的一部分)我的主要關注點是如何填寫我的字典讀取方法?我沒有使用任何參考,但不知何故無效方法返回一個值,它是如何可能的?爲什麼我的字典沒有被返回
我正在閱讀3個不同的文件。不知何故,他們都放在單個字典中,有人能告訴我確切的行嗎?
Dictionary<string, Atstovybe> Atstovybes = new Dictionary<string, Atstovybe>();
Atstovybes.Add("InfoSA", new Atstovybe("InfoSA"));
Atstovybes.Add("Statius", new Atstovybe("Statius"));
Atstovybes.Add("VfSA", new Atstovybe("VfSA"));
string[] filepaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.txt");
foreach (string file in filepaths)
{
SkaitytiDuomenis(file, Atstovybes);
}
public static void SkaitytiDuomenis(string file, Dictionary<string, Atstovybe> Atstovybes)
{
string AtstovybePav = null;
using (StreamReader reader = new StreamReader(@file))
{
string line = null;
line = reader.ReadLine();
if (line != null)
{
AtstovybePav = line;
}
Atstovybe atstovybe = Atstovybes[AtstovybePav];
while (null!= (line=reader.ReadLine()))
{
string[] values = line.Split(';');
string tema = values[0];
int sudetingumas = int.Parse(values[1]);
string autorius = values[2];
string tekstas = values[3];
string var1 = values[4];
string var2 = values[5];
string var3 = values[6];
string var4 = values[7];
string teisingas = values[8];
int balai = int.Parse(values[9]);
Klausimas klausimas = new Klausimas(tema, sudetingumas, autorius, tekstas, var1, var2, var3, var4, teisingas, balai);
atstovybe.Klausimai.Add(klausimas);
}
}
}
將您的代碼添加到您的問題中,而不是鏈接到第三方網站。它提高了在搜索中找到它的能力。 –
聽起來像你不明白參考類型如何在.NET中工作 - 我建議你閱讀http://jonskeet.uk/csharp/references.html和http://jonskeet.uk/csharp/parameters.html –
謝謝神。至少你沒有把它當作bug。 –