using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WindowsFormsApp2
{
    
    public partial class Form1 : Form
    {
        int n;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            n = 0;
            string filename = "szamok.txt";
            if (File.Exists(filename))
            {
                StreamReader streamReader = File.OpenText(filename);
                while (!streamReader.EndOfStream && n < 100)
                {
                    int val = Convert.ToInt32(streamReader.ReadLine());
                    if (val % 2 == 0)
                    {
                        listBox1.Items.Add(val);
                    }
                    else
                    {
                        listBox2.Items.Add(val);
                    }
                    Data.szamok[n] = val;
                    n++;
                }
                streamReader.Close();
            }
            else
            {
                MessageBox.Show("HIBA!!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string filename = "paros.txt";
            StreamWriter sw = File.CreateText(filename);
            for (int i = 0; i < n; i++)
            {
                if (Data.szamok[i] % 2 == 0)
                {
                    sw.WriteLine(Data.szamok[i]);
                }
            }
            sw.Close();
        }
    }

    public static class Data
    {
        public const int MAX = 100;
        public static int[] szamok = new int[MAX];
    }
}




/*
 * 
 * creation of 100 random numbers
            FileStream fs = new FileStream("szamok.txt", FileMode.Create, FileAccess.ReadWrite);
            StreamWriter streamWriter = new StreamWriter(fs);
            Random random = new Random();
            for (int i = 0; i < 100; i++)
            {
                streamWriter.WriteLine(random.Next(1, 10));
            }

            streamWriter.Close();
            fs.Close();
*/