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

Explicit value assignment in C Sharp (C#) - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Explicit Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
    }
}
A5
B1
C10
D0
Attempts:
2 left
💡 Hint
Look at the explicit value assigned to Waiting in the enum.
Predict Output
intermediate
2: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);
    }
}
A0
B10
CCompilation error
D20
Attempts:
2 left
💡 Hint
Remember that assignment returns the assigned value.
Predict Output
advanced
2: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);
    }
}
ACompilation error
B5
C0
DNullReferenceException
Attempts:
2 left
💡 Hint
Unassigned int fields in structs default to zero.
Predict Output
advanced
2: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);
    }
}
A3
B7
CCompilation error
D0
Attempts:
2 left
💡 Hint
Constants can be assigned expressions with other constants.
🧠 Conceptual
expert
2: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.
A10
B3
C11
D2
Attempts:
2 left
💡 Hint
Explicit assignment resets the counting for following members.