Challenge - 5 Problems
Strong Typing Mastery in C#
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of implicit typing with var
What is the output of this C# code snippet?
C Sharp (C#)
var x = 5; var y = "10"; var z = x + int.Parse(y); Console.WriteLine(z);
Attempts:
2 left
💡 Hint
Remember that var infers the type at compile time and int.Parse converts string to int.
✗ Incorrect
The variable x is an int with value 5, y is a string "10". int.Parse(y) converts "10" to 10. Adding 5 + 10 results in 15.
❓ Predict Output
intermediate2:00remaining
Effect of strong typing on method overloading
What will be the output of this C# program?
C Sharp (C#)
void PrintType(int x) => Console.WriteLine("int"); void PrintType(object x) => Console.WriteLine("object"); PrintType(5);
Attempts:
2 left
💡 Hint
Method overloading resolution prefers the most specific type.
✗ Incorrect
The method PrintType(int) is more specific than PrintType(object), so it is chosen for an int argument.
🔧 Debug
advanced2:00remaining
Identify the type error in this code
This code snippet causes a compile-time error. What is the cause?
C Sharp (C#)
int x = "100"; Console.WriteLine(x);
Attempts:
2 left
💡 Hint
Check the assignment of a string to an int variable.
✗ Incorrect
You cannot assign a string directly to an int variable without conversion, causing a compile-time type error.
❓ Predict Output
advanced2:00remaining
Result of casting with strong typing
What is the output of this C# code?
C Sharp (C#)
object obj = 42; int num = (int)obj; Console.WriteLine(num + 8);
Attempts:
2 left
💡 Hint
Casting from object to int is allowed if the object actually holds an int.
✗ Incorrect
The object obj holds an int 42, so casting to int succeeds. Adding 8 results in 50.
🧠 Conceptual
expert2:00remaining
Why does strong typing prevent certain bugs?
Which of the following best explains why strong typing in C# helps prevent bugs?
Attempts:
2 left
💡 Hint
Think about when type errors are detected in strongly typed languages.
✗ Incorrect
Strong typing means variables have fixed types, so the compiler can detect mismatches early, preventing many runtime errors.