The correct answer is: D. Having switched
The other options are:
- A. Switched - This is incorrect because the sentence is in the past tense, so the verb should also be in the past tense.
- B. Before - This is incorrect because it does not make sense to say "Before I went to bed, I went to bed."
- C. Switching - This is incorrect because it does not make sense to say "Switching off the light, I went to bed."
The sentence "Having switched off the light, I went to bed" means that the speaker turned off the light before going to bed. This is the most logical and grammatically correct interpretation of the sentence.