ASP.NET アプリケーションがあり、if ステートメントで列挙型を使用したいと考えています。
私はこの方法で変数を取得します:
string choice = (string)Session["export_choice"];
if(choice == <here goes enum>)
{
}
else
{
}
enum は 2 つの文字列値のみを持つことができます。
ASP.NET アプリケーションがあり、if ステートメントで列挙型を使用したいと考えています。
私はこの方法で変数を取得します:
string choice = (string)Session["export_choice"];
if(choice == <here goes enum>)
{
}
else
{
}
enum は 2 つの文字列値のみを持つことができます。
これは通常、私が使用する場所ですswitch
:
myEnumType myEnumChoice;
if (Enum.TryParse(choice, out myEnumChoice))
{
switch(myEnumChoice)
{
case myEnumType.FirstEnum:
//doSomething();
break;
case myEnumType.SecondEnum:
//doSomethingElse();
break;
}
}
else
throw new ArgumentException(string.Format("Unexpected enum value: {0}", choice));