原
现
源代码
``` using System.Drawing;
namespace 语法糖 { internal class Program { static void Main(string[] args) {
}
private Color GetColorRgb(ColorEnum colorEnum)
{
switch(colorEnum)
{
case ColorEnum.Red:
return Color.FromArgb(0, 0, 0);
case ColorEnum.Blue:
return Color.FromArgb(0, 0, 0);
case ColorEnum.Black:
return Color.FromArgb(0, 0, 0);
default:
throw new ArgumentException(
message: "invalid enum value",
paramName: nameof(colorEnum)
);
}
}
private Color GetColorRgb2(ColorEnum colorEnum)
{
return colorEnum switch
{
ColorEnum.Red => Color.FromArgb(0, 0, 0),
ColorEnum.Blue => Color.FromArgb(0, 0, 0),
ColorEnum.Black => Color.FromArgb(0, 0, 0),
_ => throw new ArgumentException(
message: "invalid enum value",
paramName: nameof(colorEnum)
)
};
}
public enum ColorEnum
{
Red,
Black,
Blue,
}
}
} ```