0
0
C Sharp (C#)programming~20 mins

Underlying numeric values in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Enum Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this enum underlying value code?

Consider the following C# code that defines an enum and prints its underlying numeric value. What will be printed?

C Sharp (C#)
enum Color { Red = 1, Green = 2, Blue = 4 }

class Program {
    static void Main() {
        Color c = Color.Blue;
        Console.WriteLine((int)c);
    }
}
A3
B0
C2
D4
Attempts:
2 left
💡 Hint

Look at the value assigned to Blue in the enum.

Predict Output
intermediate
2:00remaining
What is the output when casting enum with default underlying values?

Given this enum and code, what number is printed?

C Sharp (C#)
enum Status { Pending, Approved, Rejected }

class Program {
    static void Main() {
        Status s = Status.Approved;
        Console.WriteLine((int)s);
    }
}
A2
B0
C1
D3
Attempts:
2 left
💡 Hint

Enums start numbering from 0 by default unless specified.

Predict Output
advanced
2:00remaining
What is the output of this enum with mixed explicit and implicit values?

Analyze this code and determine the output printed.

C Sharp (C#)
enum Level { Low = 3, Medium, High = 10, Critical }

class Program {
    static void Main() {
        Console.WriteLine((int)Level.Medium);
        Console.WriteLine((int)Level.Critical);
    }
}
A4 and 11
B3 and 10
C4 and 10
D3 and 11
Attempts:
2 left
💡 Hint

Implicit values increment from the previous value.

🧠 Conceptual
advanced
1:30remaining
Which underlying type is used by default for enums in C#?

In C#, if you do not specify an underlying type for an enum, which numeric type does it use by default?

Ashort
Bint
Cbyte
Dlong
Attempts:
2 left
💡 Hint

Think about the most common integer type in C#.

Predict Output
expert
2:30remaining
What is the output of this code using Flags attribute and bitwise operations?

Consider this enum with the [Flags] attribute and the code below. What will be printed?

C Sharp (C#)
[Flags]
enum Permissions {
    None = 0,
    Read = 1,
    Write = 2,
    Execute = 4
}

class Program {
    static void Main() {
        Permissions p = Permissions.Read | Permissions.Write;
        Console.WriteLine((int)p);
    }
}
A3
B1
C2
D4
Attempts:
2 left
💡 Hint

Bitwise OR combines the numeric values.