Enumeration - Guess the Output

public enum eFormDetailType
{
    eInitialize = 1, eClear, eDelete, eFill
}

public static void Main()
{
    try
    {
        eFormDetailType FormDetailTypeItem = (eFormDetailType) 5;
        Console.WriteLine(FormDetailTypeItem);
    }
    catch
    {
        Console.WriteLine("It's an EXCEPTION");
    }
}

What is the output?

Answer: 5

Explanation: 5 does not have an enumeration to cast against, therefore the output will be 5. If another enum like "eSave" was added in, then the output would be "eSave".

No comments:

Post a Comment