Bird
Raised Fist0

What will be the output of this C# code?

medium📝 Predict Output Q13 of Q15
C Sharp (C#) - File IO
What will be the output of this C# code?
string folder = "C:\\Users\\Public";
string fileName = "report.txt";
string fullPath = Path.Combine(folder, fileName);
Console.WriteLine(fullPath);
AC:/Users/Public/report.txt
BC:\Users\Public\report.txt
CC:\Users\Publicreport.txt
DC:\Users\Public\
Step-by-Step Solution
Solution:
  1. Step 1: Understand Path.Combine behavior

    Path.Combine joins folder and file name with the correct directory separator for Windows (\).
  2. Step 2: Check the combined string output

    The result is "C:\Users\Public\report.txt" with backslashes and a single separator between folder and file.
  3. Final Answer:

    C:\Users\Public\report.txt -> Option B
  4. Quick Check:

    Path.Combine joins paths with \ [OK]
Quick Trick: Path.Combine joins paths with correct separators [OK]
Common Mistakes:
MISTAKES
  • Expecting forward slashes instead of backslashes
  • Missing separator between folder and file
  • Confusing output with folder path only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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