Bird
Raised Fist0

What will be the output of this C# code?

medium📝 Predict Output Q4 of Q15
C Sharp (C#) - File IO
What will be the output of this C# code?
string baseDir = "D:\\Documents";
string subDir = "Projects";
string combinedPath = Path.Combine(baseDir, subDir);
Console.WriteLine(combinedPath);
AD:\Documents\Projects
BD:/Documents/Projects
CD:\Documents Projects
DD:\Documents
Step-by-Step Solution
Solution:
  1. Step 1: Understand Path.Combine

    Path.Combine joins two path strings using the correct directory separator for the OS.
  2. Step 2: Combine baseDir and subDir

    Combining "D:\Documents" and "Projects" results in "D:\Documents\Projects".
  3. Final Answer:

    D:\Documents\Projects -> Option A
  4. Quick Check:

    Check for correct separator and concatenation [OK]
Quick Trick: Path.Combine joins paths with correct separators [OK]
Common Mistakes:
MISTAKES
  • Using forward slashes instead of backslashes on Windows
  • Forgetting to add a separator manually
  • Assuming spaces are added between paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes