Запись в файл работает некорректно - C#
Формулировка задачи:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace cars_information
{
class cars
{
protected string model;
protected int price;
protected int year;
public cars()
{
price = 0;
model = null;
year = 0;
}
public cars(string mod, int pr, int yr) { model = mod; price = pr; year = yr; }
public void put_in_file()
{
FileStream file = new FileStream("cars_dates.txt", FileMode.Append, FileAccess.Write);
StreamWriter writer = new StreamWriter(file,Encoding.Unicode);
while (true)
{
Console.Write("Enter a model of car: ");
model = Console.ReadLine();
Console.Write("Enter a price of car: ");
price = Convert.ToInt32(Console.ReadLine());
Console.Write("enter a price of car: ");
year = Convert.ToInt32(Console.ReadLine());
writer.WriteLine(model + " " + price + " " + year);
if (Console.Read() == 110)
{
break;
}
}
writer.Close();
}
}
class Program
{
static void Main(string[] args)
{
cars car=new cars();
car.put_in_file();
}
}
}Решение задачи: «Запись в файл работает некорректно»
textual
Листинг программы
if (Console.ReadKey().Key == ConsoleKey.N)
{
break;
}