There's a handy little method File.WriteAllLines -- no need to open a StreamWriter
yourself:
In .net 4:
File.WriteAllLines(speichern, ausgabeListe);
In .net 3.5:
File.WriteAllLines(speichern, ausgabeListe.ToArray());
Likewise, you could replace your reading logic with File.ReadAllLines, which returns an array of strings (use ToList()
on that if you want a List<string>
).
So, in fact, your complete code could be reduced to:
// Input
List<String> data = File.ReadAllLines(pfad + datei)
.Concat(File.ReadAllLines(pfad2 + datei2))
.Distinct().ToList();
// Processing
data.Sort();
// Output
data.ForEach(Console.WriteLine);
File.WriteAllLines(speichern, data);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…