0

[C#] How do I change color based on user input?

Help I am new to c# and I am trying to change the foreground color based on console.readline, is there an efficient way to do that? my method is long, inefficient and most importantly, doesn't work https://code.sololearn.com/ccc5uAmePUcp/?ref=app ^ says I put an else statement in the wrong place, but it refers to the line where I didn't even put an else statement

4th Sep 2020, 5:54 PM
Sourav Parik
2 Respuestas
+ 2
else if (color == "Green"); //<-- ; shouldn't be here There's also same mistake below on two other lines. You could make a dictionary mapping string to color, then access value by given input string. Colors won't work on SoloLearn console, btw.
4th Sep 2020, 7:37 PM
BlazingMagpie
BlazingMagpie - avatar
+ 1
In addition to color not working on SoloLearn for C#, your code is reading input twice. If you are providing both these inputs on separate lines when you first compile, that's okay, but SL won't let you pause for new input in the middle of execution with C#.
4th Sep 2020, 7:57 PM
Roy Mullis
Roy Mullis - avatar