Hello

This year I am taking OOP as a core course and I am starting with C#..

So my first code to accomplish is to make an array of information about different types of cars..

In a brief.. It consists of 2 forms, The first form is where the user enter the car information accompanied with its index in the array like : 0, 1 , 2 with a button to Submit it..

In the Second form - where it is opened from the first via a button - , The user enters the car Index and press a button to view the data into a multi-line text box..

I am still learning, so I haven't gone far with the code but this..

Source Codes:

1. Car.cs
Accomplishments : Creating constructors for the array, ReadInfo to read the inputs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Arrays_Objects
{
    class car
    {
        string factory, modelname;
        int year, tanksize;
        double price;

        public car()
        {
        }


        public car(string Factory, string ModelName, int Year, int TankSize, double Price)
        {
            factory = Factory;
            modelname = ModelName;
            year = Year;
            tanksize = TankSize;
            price = Price;
        }

        public void ReadInfo(string Factory, string ModelName, int Year, int TankSize, double Price)
        {
            factory = Factory;
            modelname = ModelName;
            year = Year;
            tanksize = TankSize;
            price = Price;
        }

    }
}

2. Form1.cs
Accomplishments : Creating array and allocating it. Adding some options for the user to select from. Linking Form2 to Form1

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

namespace Arrays_Objects
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            car[] y = new car[10];  // Creating an Array of 10

            for (int k = 0; k < 10; k++) // Allocating the Arrays
            {
                y[k] = new car(); 
            }

            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox3.Items.Clear();
            if (comboBox2.Text == "Honda")
            {
                comboBox3.Items.Add("Civic");
                comboBox3.Items.Add("Jazz");
                comboBox3.Items.Add("Accord");
            }

            else if(comboBox2.Text == "Mercedes Benz")
            {
                comboBox3.Items.Add("C180");
                comboBox3.Items.Add("B160");
                comboBox3.Items.Add("E250");
            }

            else if (comboBox2.Text == "BMW")
            {
                comboBox3.Items.Add("116i");
                comboBox3.Items.Add("330i");
                comboBox3.Items.Add("525i");
            }
            
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            Form2 newForm = new Form2();
            newForm.Show();
        }

        private Form2 newForm;
    }
}

3. Form2.cs
Accomplishments :Just the Design so far

What I need help with:
1. The "Submit" button to save the entered data into the textboxs... How can I take the data into the text box and save it into the array ... No care about the index number because the array is limited to 10 blocks only..

2. How to view this info into a multiline textbox in form 2 when the user supply the car index.. No problem either if it is a number more than 10...

N.B. For the textbox numbers, pleas just refer to what will be written in it such as, Tank Size, etc..
They are found in the car class.

If the Form Design will help, please tell me to supply it.

I hope I am organized enough to show what I need help with...

Thanks in advance :)

Anyone could help ?

OK your car class needs properties.Read/Write.Everytime you make a new car you will add your class in a collection of car classes by means of a List<Car>. Based on the users input you will get the spesific car object from your collection and send it to the second form.

Im at work atm ill be happy to show you some examples if you want.Think its just better this way than to use arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.