Необходимо чтобы данные введённые с клавиатуры записывались в текстовый документ,но не записывает

Необходимо чтобы данные введённые с клавиатуры записывались в текстовый документ,но не записывает код:

введите сюда код





struct User
    {
        public string stamp; //марка
        public int year; //год выпуска
        public string country; //страна производитель
        public string model; //модель
        public string body; //тип кузова
        public int bodyInt; //номер кузова
        public string box; //коробка передач
        public string drive; //привод
}
class Program
    {
        static void Main(string[] args)
        {
            StreamWriter F = new StreamWriter("Z://text1.txt");

            Console.WriteLine("Stamp:");
            string stamp = Console.ReadLine();
            Console.WriteLine("Year:");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Country:");
            string country = Console.ReadLine();
            Console.WriteLine("Model:");
            string model = Console.ReadLine();
            Console.WriteLine("Body:");
            string body = Console.ReadLine();
            Console.WriteLine("BodyInt:");
            int bodyInt = int.Parse(Console.ReadLine());
            Console.WriteLine("Box:");
            string box = Console.ReadLine();
            Console.WriteLine("Drive:");
            string drive = Console.ReadLine();
            Console.ReadKey();

            F.Close();
   }
}

Ответы (1 шт):

Автор решения: MRXIT
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;

#pragma warning disable SYSLIB0011

namespace Application
{
    [Serializable]
    [StructLayout(LayoutKind.Sequential)]
    public struct User
    {
        public string Stamp;
        public int Year;
        public string Country;
        public string Model;
        public string Body;
        public int BodyInt;
        public string Box;
        public string Drive;
    }

    internal sealed class Core
    {
        private static void Main()
        {
            Console.WriteLine("Stamp:");
            string stamp = Console.ReadLine();
            Console.WriteLine("Year:");
            int year = int.Parse(Console.ReadLine());
            Console.WriteLine("Country:");
            string country = Console.ReadLine();
            Console.WriteLine("Model:");
            string model = Console.ReadLine();
            Console.WriteLine("Body:");
            string body = Console.ReadLine();
            Console.WriteLine("BodyInt:");
            int bodyInt = int.Parse(Console.ReadLine());
            Console.WriteLine("Box:");
            string box = Console.ReadLine();
            Console.WriteLine("Drive:");
            string drive = Console.ReadLine();
            Console.ReadKey();

            User user = new User() { Stamp = stamp, Year = year,
                Country = country, Model = model, Body = body,
                BodyInt = bodyInt, Box = box, Drive = drive };

            Serialize(user);

            User newUser = (User)Deserialize();

            Console.WriteLine(newUser.Stamp);
        }

        private static void Serialize(object obj)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (FileStream fileStream = new FileStream("user.dat", FileMode.OpenOrCreate))
                binaryFormatter.Serialize(fileStream, obj);
        }

        private static object Deserialize()
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            using (FileStream fileStream = new FileStream("user.dat", FileMode.OpenOrCreate))
                return binaryFormatter.Deserialize(fileStream);
        }
    }
}
→ Ссылка