Bird
Raised Fist0

Why does Path.Combine ignore the first path if the second path is an absolute path?

hard🧠 Conceptual Q10 of Q15
C Sharp (C#) - File IO
Why does Path.Combine ignore the first path if the second path is an absolute path?
ABecause Path.Combine always returns the first path only
BBecause the second path overrides the first as it is absolute
CBecause absolute paths are invalid in Path.Combine
DBecause Path.Combine throws an exception on absolute second path
Step-by-Step Solution
Solution:
  1. Step 1: Understand Path.Combine behavior with absolute paths

    If the second path is absolute, Path.Combine returns it ignoring the first path.
  2. Step 2: Reason why this happens

    Absolute paths are complete paths, so combining with another path would be incorrect; hence it overrides.
  3. Final Answer:

    Because the second path overrides the first as it is absolute -> Option B
  4. Quick Check:

    Absolute second path overrides first in Path.Combine [OK]
Quick Trick: Absolute second path replaces first in Path.Combine [OK]
Common Mistakes:
MISTAKES
  • Thinking Path.Combine returns first path always
  • Assuming absolute paths are invalid
  • Expecting exceptions on absolute paths

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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