这是使用恩斯姆的好例子吗? 或者使用数组会更好吗? 这里的价值观不会改变,也许每年说一次。这是Enums的正确使用吗?
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();
}
}
}
如果您的标题与您的问题内容相符,这将有助于提高答案的质量。标题询问这是否是正确的用法,问题不在于,问题是否这是最佳的操作方法与查询列表,这是有争议的。 –