这段代码的工作原理,但我不明白其背后的原因(它只是程序的一部分)我的主要关注点是如何填写我的字典读取方法?我没有使用任何参考,但不知何故无效方法返回一个值,它是如何可能的?为什么我的字典没有被返回
我正在阅读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。 –