Generic Approch
Generic Approch
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Evidence_Exam_Generic_Approch
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
Car<string> car = new Car<string>("COROLA", 25000000, 2021, 40.5F, "GAS", "Color: Rad",
"Seat Color: Black", "Headlight: LED");
car.Display();
motor.Display();
Console.Read();
}
}
public enum VehicleType
{
FourWheeler,
TwoWheeler
}
protected Vehicle(string model, decimal price, int year, float mileage, string fuel, VehicleType
VehicleType)
{
this.Model = model;
this.Price = price;
this.YearMake = year;
this.Mileage = mileage;
this.FuelType = fuel;
this.VehicleType = VehicleType;
}
public abstract void Display();
}
}
public sealed class Car<T> : FourWheeler<T> where T : class
{
public Car(string model, decimal price, int year, float mileage, string fuel, params T[] InteriorDesign) :
base(model, price, year, mileage, fuel, InteriorDesign)
{}
public override void Display()
{
Console.WriteLine("Car info:");
Console.WriteLine("Type:" + this.VehicleType);
Console.WriteLine("Model:" + this.Model);
Console.WriteLine("Price:" + this.Price);
Console.WriteLine("Year:" + this.YearMake);
Console.WriteLine("Mileage:" + this.Mileage);
Console.WriteLine("Fuel:" + this.FuelType);
foreach (var design in this.InteriorDesign)
{
Console.WriteLine(design);
}
Console.WriteLine();
}
}
public interface ITwoWheeler<T> where T : class
{
T[] ExteriorDesign { get; set; }
}
public class TwoWheeler<T> : Vehicle, ITwoWheeler<T> where T : class
{
public T[] ExteriorDesign { get; set; }
public TwoWheeler(string model, decimal price, int year, float mileage, string fuel, params T[]
ExteriorDesign) : base(model, price, year, mileage, fuel, VehicleType.TwoWheeler)
{
this.ExteriorDesign = ExteriorDesign;
}
public override void Display()
{
}
}
public sealed class Motorcycle<T> : TwoWheeler<T> where T : class
{
public Motorcycle(string model, decimal price, int year, float mileage, string fuel, params T[]
ExteriorDesign) : base(model, price, year, mileage, fuel, ExteriorDesign)
{}
public override void Display()
{
Console.WriteLine("Motorcycle info:");
Console.WriteLine("Type:" + this.VehicleType);
Console.WriteLine("Model:" + this.Model);
Console.WriteLine("Price:" + this.Price);
Console.WriteLine("Year:" + this.YearMake);
Console.WriteLine("Mileage:" + this.Mileage);
Console.WriteLine("Fuel:" + this.FuelType);
foreach (var design in this.ExteriorDesign)
{
Console.WriteLine(design);
}
Console.WriteLine();
}
}
}