Why is my C# code editor so little intuititve? I am aware xValue needs to have an assigned value but I should not apply it by default.
There's no way for the compiler to know whether or not xValue will actually ever be assigned a value, since it cannot evaluate that either condition (direction == "l" or direction == "r") will ever be true at runtime. Therefore, xValue might be left uninitialized when it is accessed later on. In short: always gives your variables a value. It's good practice, will help avoid unexpected behavior, and your compiler / IDE won't complain.
add else throw new Exception() and it will work edit: Your code is not robust because the code can take paths not indented
Programs only do exactly what you tell them to do. With the way you have this structured, you are telling the compiler that it is possible for xValue to remain unassigned, therefore it will take this possibility into account. The problem here isn't with Visual Studio, it's with the way the logic was written.
If your direction choices are only "l" or "r", then just do an if check for one of them and make the other an else statement only. Then you'll have an if/else statement which means it will have one value or the other.