내 프로그램이 두 개의 텍스트 파일을 하나의 List<T>
으로 읽으 려합니다. List<T>
은 중복 된 항목을 정렬하고 정리합니다.리스트에서 저장 <T> to txt
List<T>
(정렬 및 청소 후)을 txt 파일에 저장하려고합니다.
하지만 결과 txt 파일에서 보았을 때, 나는이 메시지를 발견
System.Collections.Generic.List`1는 [선택 System.String]
누구 아이디어가 있습니까을 이 오류를 어떻게 해결할 수 있습니까?
StreamWriter file = new System.IO.StreamWriter(speichern);
file.WriteLine(ausgabeListe);
file.Close();
가 대신 각 줄을 쓰고 싶은 : 그것은 당신이있어 텍스트 행에 결과 목록의 toString 표현을 씁니다이 줄의
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Uniqpass
{
class Program
{
static void Main(string[] args)
{
String pfad = "C:\\Dokumente und Einstellungen\\Bektas\\Desktop\\test\\";
String pfad2 = "C:\\Dokumente und Einstellungen\\Bektas\\Desktop\\test\\";
String speichern = "C:\\Dokumente und Einstellungen\\Bektas\\Desktop\\test\\ausgabe.txt";
String datei = "text1.txt";
String datei2 = "text2.txt";
try
{
//Einlesen TxT 1
List<String> pass1 = new List<String>();
StreamReader sr1 = new StreamReader(pfad + datei);
while (sr1.Peek() > -1)
{
pass1.Add(sr1.ReadLine());
}
sr1.Close();
//Einlesen TxT 2
StreamReader sr2 = new StreamReader(pfad2 + datei2);
while (sr2.Peek() > -1)
{
pass1.Add(sr2.ReadLine());
}
sr2.Close();
List<String> ausgabeListe = pass1.Distinct().ToList();
ausgabeListe.Sort();
ausgabeListe.ForEach(Console.WriteLine);
StreamWriter file = new System.IO.StreamWriter(speichern);
file.WriteLine(ausgabeListe);
file.Close();
}
catch (Exception)
{
Console.WriteLine("Error");
}
Console.ReadKey();
}
}
}
환상적인 답변입니다. 정확히 내가 필요로하는 것. –
이 답변은 잠재적으로 여러 줄의 코드를 한 줄로 줄이기 때문에 좋습니다. – Free2Rhyme2k
@ Free2Rhyme2k : 예, 코드 줄이 적어 대개 버그가 적습니다. – Heinzi