Unity/수업내용(C#)
[3.10] 콘솔창 색 바꾸기 (번외)
ljw4104
2021. 3. 10. 13:13
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study01
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
Console.BackgroundColor = ConsoleColor.Red;
Console.ForegroundColor = ConsoleColor.White;
Console.Write("정수 입력 : ");
int data = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i < 10; i++)
{
Console.WriteLine("{0} * {1} = {2}", data, i, data * i);
}
}
}
}
색깔들은 ConsoleColor라는 enum 자료형으로 모여있다.
BackgroundColor은 두 번 사용할 수 있는데, 첫번째로 사용시 콘솔배경색이 바뀌고 두번째로 사용하면 폰트에 배경색으로 입혀진다.
콘솔배경색을 바꾼 첫번째 이후로 Console.clear()라는 함수를 사용해주어야 한다.