표준 출력

정영훈·2022년 8월 23일
0

C#프로그래밍

목록 보기
3/29

표준 출력

Console.WriteLine()

  • c# 프로그래밍의 가장 기본 출력방법
  • System 네임스페이스의 Console 클래스의 WriteLine() 메서드
  • System.Console.WrireLine();

Console.Write()

  • Console.WroteLine()은 개행(\n)이 되지만 Console.Write()는 개행이 되지 않는다.
Console.WriteLine("hello, world");
Console.Write("hello, ");
Console.Write("world");

using static System.Console;

  • using System을 사용하면 System이라는 네임스페이스를 선언하지 않아도 되지만 Console이라는 메서드도 사용하기 싫을 때는 using static System.Console; 선언하여 사용할 수 있다.
using static System.Console;
WriteLine("hello, world\n");

변수값 출력하기

  • 변수의 값만 출력 : Console.WriteLine(a);
  • 서식에 맞춰 출력 : Console.WriteLine("a={0}, b={1}",a,b);
  • 문자열 보간 : Console.WriteLine($"a={a}, b={b}");
profile
경북소프트웨어고등학교 정보교사

0개의 댓글