根據微軟的官方文件記載
Enum.Parse 方法可以將列舉常數的名稱或數值傳換成相等的列舉物件(Sample code 如下所式)
Converts the string representation of the name or numeric value of one or more enumerated constants to an equivalent enumerated object.
enum ExitCodes : int
{
Success = 0,
SignToolNotInPath = 1,
AssemblyDirectoryBad = 2,
PFXFilePathBad = 4,
PasswordMissing = 8,
SignFailed = 16,
UnknownError = 32
}
Sample code :
int code =0;
ExitCodes value = (ExitCodes )Enum.Parse(typeof (ExitCodes ), code.ToString());
System.Console.WriteLine(value .ToString());
|
Output:
Success
|
留言
張貼留言