C#/문법 정리
C# - Console.WriteLine() 메서드
Khadra
2024. 6. 13. 09:22
Console.WriteLine()
하나의 변수나 값을 출력할 때 어떤 자료형이든 출력이 가능하다.
여러가지 자료형에 대해 중복(overload)되어 있기 때문이다.
예제
여러가지 자료형의 변수들을 출력하는 예제
- 변수나 값을 출력하면 자료형마다 디폴트로 정해진 형식으로 콘솔에 출력된다.
using System;
using static System.Console;//Console단어를 생략(코드길이줄어둠)
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
bool b = true;
char c = 'A';
decimal d = 1.234m; //m은 decimal 형의 접미사
double e = 1.23456789;
float f = 1.23456789f; //f은 float 형의 접미사
int i = 1234;
string s = "Hello";
WriteLine(b);
WriteLine(c);
WriteLine(d);
WriteLine(e);
WriteLine(f);
WriteLine(i);
WriteLine(s);
}
}
}
결과
// True
// A
// 1.234
// 1.23456789
// 1.2345679
// 1234
// Hello