Ask coding questions

← Back to all posts
Why isn't it rendering the Multi-Dimensional Array? *fixing it.*
JSuser2021

I just started to learn C Sharp and Very Recently, I was making a text-based mover game in the console (where all you can do is, well, move around). I got this error of 'unreachable code detected' and I don't know why. maybe you could check the code?

Update: I fixed it but I got another problem: It won't render the Multi-Dimensional Array at all.

Voters
JSuser2021
Comments
hotnewtop
SixBeeps

Okay now you're code is trying to append to line but line doesn't have a value. In C#, strings aren't given "" as a default value, so you'll need to explicitly set it to an empty string literal before doing anything with it.

SixBeeps

Looks like you got rid of it, nice.

To clarify, the "unreachable code" message is just a warning, not an error. It shows up whenever a section of code cannot logically be ran at any point. For example:

In this code block, Console.WriteLine never gets invoked because the method returns before it can be ran. There are more ways than just this to cause unreachable code, but this is the most common one I've ran into.