0

Разрабатываю программу , в которой необходимо ввести количество авто, их характериститики и вывести все характеристики на экран.При выводе возникает ошибка:Ссылка на объект не указывает на экземпляр объекта.

Код классов:

    namespace лб3
{
    class Auto
    {
        public string marka;
        public string model;
        public string countryrelease;
        public string color;
        public string price;
        public virtual void show_info()
        {
            MessageBox.Show("Авто " + ": " + marka + "  " + model + "  " +
                                                    countryrelease + "  " + color + "  " + price);

        }


    }

    class Passengercar : Auto
    {
        public string rwheels;
        public override void show_info()
        {

            MessageBox.Show("Легковое авто " + ": " + marka + "  " + model + "  " +
                                                   countryrelease + "  " + color + "  " + price + "  " + rwheels);
        }

        public void all_price(ref int i, ref int summ)
        {

            summ = summ + Convert.ToInt32(price);
        }

    }

Код формы:

namespace лб3
{
    public partial class Form1 : Form
    {
        int k;
        public Form1()
        {
            InitializeComponent();

        }

        public void textBox1_TextChanged(object sender, EventArgs e)
        {
             k = Convert.ToInt32(textBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            textBox8.ReadOnly = true; textBox9.ReadOnly = true;
            MessageBox.Show("Введите характеристики  авто");
        }

        private void label1_Click(object sender, EventArgs e)
        {
        }


        int i = 0;
        public void button2_Click(object sender, EventArgs ei)
        {

            Passengercar[] smallcar = new Passengercar[k];
            smallcar[i] = new Passengercar();       
            smallcar[i].marka = textBox2.Text;
            smallcar[i].model = textBox3.Text;
            smallcar[i].countryrelease = textBox4.Text;
            smallcar[i].color = textBox5.Text;
            smallcar[i].price = textBox6.Text;
            smallcar[i].rwheels = textBox7.Text;
            i++;
            if (i<k)
            {
                MessageBox.Show("Введите характеристики" + i + "-го легкового авто");
            }
        }

        public void button3_Click(object sender, EventArgs e)
        {
            for(int j = 0; j < k; j++)
            {
                Passengercar[] smallcar = new Passengercar[k];
                smallcar[j].show_info();
            }

        }
    }

0 Answers0