본문으로 바로가기

안녕하세요. 이솔찬입니다.

이번에는 C#으로 Hello World를 출력해보겠습니다.


C#에서는 기본으로 콘솔 화면에 메시지를 출력하는 코드는 다음과 같습니다.


1
Console.WriteLine("Hello World!");
cs


먼저 Visual Studio에서 새 프로젝트 추가하고

아래 사진과 같이 설정합니다.



프로젝트가 만들어지면 다음 코드가 있습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hello_World
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}
cs


12~13줄에 엔터키를 눌러서 한 줄을 추가하고

다음 코드를 입력합니다.


1
Console.WriteLine("Hello World!");
cs


전체 코드는 다음과 같습니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Hello_World
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}
cs


이제 Ctrl + F5키를 눌러서 실행합니다.


Hello World!가 출력됩니다.



VIsual Studio에서 F5키만 누르고 실행하면 cmd가 열리자마자 바로 닫힙니다.

닫히지 않게 하려면 다음 코드를 메시지 출력 함수 다음 줄에 추가하면 됩니다.


1
Console.ReadKey();
cs


만든 프로그램 실행 파일(.exe)는 프로젝트 경로/프로젝트 이름/bin/Debug 폴더에 있습니다.



예제 파일 다운로드:


프로젝트 파일:

Hello World C#.zip


완성 파일(간편설치기로 설치):

[Lee_SolChan]Hello_World_C#_Setup.exe

'C# 강의 > 콘솔 다루기' 카테고리의 다른 글

C# 강의 - do~while 문  (0) 2019.02.18
C# 강의 - for 문  (0) 2019.02.16
C# 강의 - 4. 연산자  (0) 2019.02.14
C# 강의 - 3. 함수 정의 및 사용  (0) 2019.02.10
C# 강의 - 2. int, float, bool, string 변수  (0) 2019.02.02