Pass enum data to a method
using System;
public enum LineStyle
{
Solid,
Dotted,
DotDash,
}
class MainClass
{
public static void Main()
{
DrawLine(LineStyle.Solid);
DrawLine((LineStyle) 35);
}
public static void DrawLine(LineStyle lineStyle)
{
switch (lineStyle)
{
case LineStyle.Solid:
Console.WriteLine("draw solid");
break;
case LineStyle.Dotted:
Console.WriteLine("draw dotted");
break;
case LineStyle.DotDash:
Console.WriteLine("draw dotdash");
break;
default:
throw(new ArgumentException("Invalid line style"));
}
}
}
Output draw solid
Unhandled Exception: System.ArgumentException: Invalid line style
at MainClass.DrawLine(LineStyle lineStyle)
at MainClass.Main()
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
-
-
-
|