Cześć, mam taki problem, lecę sobie z zadaniami z Fundamentals of Computer Programming with C#: The Bulgarian C# Book i jedno z ćwiczeń to napisanie programu który dodaje do siebie dwa teksty. Oto co napisałem:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace ConsoleApp67
{
class Program
{
static void Main(string[] args)
{
StreamReader reader1 = new StreamReader("text1.txt");
StreamReader reader2 = new StreamReader("text2.txt");
StreamWriter writer = new StreamWriter("output.txt",true);
using (reader1)
{
string lane1 = reader1.ReadLine();
using (writer)
{
while (lane1 != null)
{
writer.WriteLine(lane1);
lane1 = reader1.ReadLine();
}
}
}
using(reader2)
{
string lane2 = reader2.ReadLine();
using(writer)
{
while(lane2 !=null)
{
writer.WriteLine(lane2);
lane2 = reader2.ReadLine();
}
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
I dostaję taki błąd System.ObjectDisposedException: 'Nie można zapisać danych w zamkniętym elemencie TextWriter.', wywala mi to w linijce writer.WriteLine(lane2); Czym jest to spowodowane?