• I removed the www from the URL, please update your bookmarks and pay attention to the bottom of the screen if using Google Chrome to allow push notifications again.

Question Color

porkshopp

Active member
Joined
Apr 13, 2019
Messages
26
Location
Sweden
Programming Experience
Beginner
How can I make an item in my array a specific color?
Code:
 Bo[answer - 1] = "X"; Console.ForegroundColor = ConsoleColor.Green;
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,230
Location
Sydney, Australia
Programming Experience
10+
You're going to have to be more specific. Are you simply saying that you want to display the next text you write to the console in a particular colour or you want a specific element in an array to always be displayed in a specific colour?
 

porkshopp

Active member
Joined
Apr 13, 2019
Messages
26
Location
Sweden
Programming Experience
Beginner
I want to edit a specific element in the array and set a colored text, but it should only be that element that has that color, the others should not be impacted. So if I have an array that outputs: "A", "B", "C". It should now output "A", "B", "C" but the B is green. This should also be done inside another method
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
2,230
Location
Sydney, Australia
Programming Experience
10+
A String has no colour so you will need to store the colour along with the text somehow and then, whenever you display a text value, you do so using the associated colour. For instance, you might define a class with a property of type String and another of type ConsoleColor and store instances of that in an array instead of just Strings.
 
Top Bottom