Challenge - 5 Problems
Explicit Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of explicit enum value assignment
What is the output of this C# program?
C Sharp (C#)
enum Status { Ready = 1, Waiting = 5, Complete = 10 } class Program { static void Main() { Status s = Status.Waiting; System.Console.WriteLine((int)s); } }
Attempts:
2 left
💡 Hint
Look at the explicit value assigned to Waiting in the enum.
✗ Incorrect
The enum Status assigns Waiting the value 5 explicitly. Casting it to int prints 5.
❓ Predict Output
intermediate2:00remaining
Value of explicitly assigned variable
What value is printed by this C# code?
C Sharp (C#)
class Program { static void Main() { int x = 10; int y = x = 20; System.Console.WriteLine(y); } }
Attempts:
2 left
💡 Hint
Remember that assignment returns the assigned value.
✗ Incorrect
The expression x = 20 assigns 20 to x and returns 20, which is then assigned to y.
❓ Predict Output
advanced2:00remaining
Output of explicit struct field assignment
What is the output of this C# program?
C Sharp (C#)
struct Point {
public int X;
public int Y;
}
class Program {
static void Main() {
Point p = new Point { X = 5 };
System.Console.WriteLine(p.Y);
}
}Attempts:
2 left
💡 Hint
Unassigned int fields in structs default to zero.
✗ Incorrect
Since Y is not assigned, it defaults to 0 in the struct.
❓ Predict Output
advanced2:00remaining
Output of explicit constant value assignment
What does this C# code print?
C Sharp (C#)
class Program { const int a = 3; const int b = a + 4; static void Main() { System.Console.WriteLine(b); } }
Attempts:
2 left
💡 Hint
Constants can be assigned expressions with other constants.
✗ Incorrect
b is assigned a + 4, which is 3 + 4 = 7.
🧠 Conceptual
expert2:00remaining
Effect of explicit value assignment on enum underlying values
Given this enum declaration, what is the value of Color.Blue?
enum Color { Red = 2, Green, Blue = 10, Yellow }
Choose the correct value of Color.Blue.
Attempts:
2 left
💡 Hint
Explicit assignment resets the counting for following members.
✗ Incorrect
Blue is explicitly assigned 10, so its value is 10, not 3 or 11.