• 1405/08/25

تمرین جلسه 39(پلاک ماشین) :

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

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {

                Car car1 = new Car(txtColor.Text, txtPlate.Text , txtName.Text);

                lblResult.Text = $"{car1.CarName} رنگ {car1.CarColor}" +
                    $"\n پلاک : {car1.CarPlate}" +
                    $"\n مجاز به ورود است!";
            }
            catch
            {
                MessageBox.Show("پلاک نامعتبر");
            }
        }

        private void txtPlate_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
using System;
using System.Collections.Generic;
using System.Text;

namespace Car_Permision01
{
    internal class Car
    {
        public Car(string Color, string Plate , string Name)
        {
            CarName = Name;

            CarColor = Color;

            if (Plate.Length < 6)
            {
                throw new Exception("Invalid Input");
            }
            else
            {
                CarPlate = Plate;
            }
        }

        public string CarColor { get; }
        public string CarPlate { get; }
        public string CarName { get; }
    }
}
  • 1405/08/25
  • ساعت 07:14

بسیار عالی بود