From 3914bd51bb9a30bdef71db054fb5d7c6bb2ce86c Mon Sep 17 00:00:00 2001 From: YourDax Date: Tue, 28 Nov 2023 12:06:24 +0400 Subject: [PATCH] fix with streamreader --- .../Generics/AntiAirCraftGunGenericCollection.cs | 2 +- .../Generics/AntiAirCraftGunGenericStorage.cs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs index 0dd9a20..35d8926 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericCollection.cs @@ -130,7 +130,7 @@ namespace AntiAircraftGun.Generics foreach (var zenit in _collection.GetZenits()) { - // TODO: Получение объекта + T? obj = zenit; if (obj != null) diff --git a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericStorage.cs b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericStorage.cs index 30b7fae..c6bbbec 100644 --- a/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericStorage.cs +++ b/AntiAirCraftGun/AntiAirCraftGun/Generics/AntiAirCraftGunGenericStorage.cs @@ -129,11 +129,16 @@ namespace AntiAircraftGun.Generics { return false; } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new - UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); - return true; + string toWrite = $"CarStorage{Environment.NewLine}{data}"; + var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + using (StreamWriter sw = new(filename)) + { + foreach (var str in strs) + { + sw.WriteLine(str); + } + } + return true; } /// /// Загрузка информации по автомобилям в хранилище из файла