這是使用恩斯姆的好例子嗎? 或者使用數組會更好嗎? 這裏的價值觀不會改變,也許每年說一次。這是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();
}
}
}
如果您的標題與您的問題內容相符,這將有助於提高答案的質量。標題詢問這是否是正確的用法,問題不在於,問題是否這是最佳的操作方法與查詢列表,這是有爭議的。 –