Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- namespace lab2I
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = 5;
- int[] arr = new int[n];
- for( int i = 0; i < n; i++ ){
- Console.Write("Введите " + ( i + 1 ) + " число массива: ");
- arr[i] = int.Parse(Console.ReadLine());
- }
- string fileName = "file.bin";
- var write_file = File.Open(fileName, FileMode.Create);
- var writer = new BinaryWriter(write_file);
- for( int i = 0; i < n; i++ ){
- writer.Write( arr[i] );
- }
- writer.Close();
- write_file.Close();
- var read_file = File.Open(fileName, FileMode.Open);
- var reader = new BinaryReader(read_file);
- for( int i = 0; i < n; i++ ){
- arr[i] = reader.ReadInt32();
- }
- reader.Close();
- read_file.Close();
- Console.WriteLine("Содержимое файла");
- for( int i = 0; i < n; i++ ){
- Console.WriteLine( arr[i] );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement