Is this a good case to use enmus?
Or would it be better to use an array?
The values here wouldn’t change maybe say once a year.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public enum transmission
{
Manual,
NonSynchronous,
Automatic,
SemiAutomatic,
Continuously,
Infinitely,
Electric,
Hydrostatic,
Hydrodynamic,
}
public enum bodystyle
{
Convertable,
Hatchback,
Sports,
Sedan
}
public enum carcolors
{
Red,
Blue,
Yellow,
White,
Black,
Green
}
public enum fueltype
{
Biofuels,
FossilFuels,
Nuclear,
Fission,
Fusion
}
public class Car
{
public Car(String cName, double cMaxSpeed, String cTransmission, String cBodystyle, String cColors, String cFueltype) {
carname = cName;
transmission = cTransmission;
bodystyle = cBodystyle;
colors = cColors;
fueltype = cFueltype;
maxspeed = cMaxSpeed;
}
public string carname
{
get;
set;
}
public string transmission
{
get;
private set;
}
public string bodystyle
{
get;
private set;
}
public string colors
{
get;
private set;
}
public string fueltype
{
get;
private set;
}
public void carInfo()
{
Console.WriteLine("------------------------------------");
Console.WriteLine("Car Name: " + this.carname);
Console.WriteLine("Car Transmission: " + this.transmission );
Console.WriteLine("Car Bodystyle: " + this.bodystyle);
Console.WriteLine("Car Colors: " + this.colors);
Console.WriteLine("Car Fueltype: " + this.fueltype);
Console.WriteLine("Car MaxSpeed: " + this.maxspeed);
Console.WriteLine("------------------------------------");
}
}
public class Program
{
static void Main(string[] args)
{
Car nissan = new Car("Lamborgini", 255, Convert.ToString(transmission.Automatic), Convert.ToString(bodystyle.Sports), Convert.ToString(carcolors.Red), Convert.ToString(fueltype.Biofuels));
nissan.carInfo();
}
}
}
You have defined several
Enumtypes, but are not actually using them. So, in this respect, not a proper usage.In regards to using an array – I don’t see the value of that over enums.
The types you are passing in are all
string, rather than theEnumtypes as are the types of your properties.A proper usage would look like: