好久沒開始C and P了 (Copy and Paste) 來記Blog....
現在開始吧.......
from Mark Wagner's .NET C# Cogitation
現在開始吧.......
from Mark Wagner's .NET C# Cogitation
Convert a string to an enumprivate enum Aircraft
{
Beech,
Cessna,
Piper
}You can easily convert the string to an enum value like this:
Aircraft air = (Aircraft) Enum.Parse(typeof(Aircraft), "Cessna", true);
Ideally you should wrap a try-catch around the Enum.Parse statement.
rated (enum) value