Answer to Question #264266 in C# for Shree

Question #264266

Define a class with constructor,fields and properties

1
Expert's answer
2021-11-11T07:30:29-0500
using System;
using System.Collections.Generic;


namespace App
{
    class Car
    {
        private int registrationNumber;


        public int RegistrationNumber
        {
            get { return registrationNumber; }
            set { registrationNumber = value; }
        }
        private string model;


        public string Model
        {
            get { return model; }
            set { model = value; }
        }
        private string colour;


        public string Colour
        {
            get { return colour; }
            set { colour = value; }
        }
        private double price;


        public double Price
        {
            get { return price; }
            set { price = value; }
        }


        public Car()
        {


        }
        public Car(int registrationNumber, string model, string colour, double price)
        {
            this.registrationNumber = registrationNumber;
            this.model = model;
            this.colour = colour;
            this.price = price;
        }




    }


    class Program
    {




        static void Main(string[] args)
        {


            var c1 = new Car(5646321, "Ford X5", "Red", 45000);
            var c2 = new Car(7894546, "Ford X8", "Blue", 5000);
            var c3 = new Car(8745565, "Reno X45", "Yellow", 95050);




            Console.ReadLine();
        }




    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS