Filestream. Не происходит запись в файл - C#
Формулировка задачи:
Изначально строки из файла считываются и выводятся на консоль. После я записываю структурный массив в файл, но ничего не появляется.
Листинг программы
- class task
- {
- static void Main(string[] args)
- {
- FileStream F = new FileStream("data1.txt", FileMode.Open, FileAccess.ReadWrite);
- StreamReader r = new StreamReader(F, Encoding.Default);
- string s = r.ReadToEnd();
- Console.WriteLine(s);
- F.Flush();
- Console.WriteLine();
- Console.Write("Введите количество человек: ");
- int n = Convert.ToInt32(Console.ReadLine());
- book[] mass = new book[n];
- Mass(mass);
- StreamWriter wr = new StreamWriter(F, Encoding.Default);
- wr.Write(mass);
- F.Flush();
- F.Close();
- Console.ReadKey();
- }
- struct book
- {
- public string Name;
- public string SurName;
- public string Email;
- public Number BuyNumber;
- }
- struct Number
- {
- public long Home;
- public long Mob1;
- public long Mob2;
- public long Work;
- }
- static book[] Mass(book[] mass)
- {
- for (int i = 0; i < mass.Length; i++)
- {
- Console.WriteLine("Введите данные {0}-ого человека", i + 1);
- Console.Write("Фамилия:");
- mass[i].SurName = Console.ReadLine();
- Console.Write("Имя:");
- mass[i].Name = Console.ReadLine();
- Console.Write("email:");
- mass[i].Email = Console.ReadLine();
- Console.Write("Мобильный номер 1:");
- mass[i].BuyNumber.Mob1 = Convert.ToInt32(Console.ReadLine());
- Console.Write("Мобильный номер 2:");
- mass[i].BuyNumber.Mob2 = Convert.ToInt32(Console.ReadLine());
- Console.Write("Домашний номер:");
- mass[i].BuyNumber.Home = Convert.ToInt32(Console.ReadLine());
- Console.Write("Рабочий номер:");
- mass[i].BuyNumber.Work = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine();
- }
- return mass;
- }
- }
Решение задачи: «Filestream. Не происходит запись в файл»
textual
Листинг программы
- using (StreamWriter wr = new StreamWriter(F, Encoding.Default))
- wr.Write(mass);
- Console.ReadKey();
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д