C# 기초

Hello World in C#: Structure of a Console Program

Write your first C# program and see what each part does: using, class Program, Main and Console.WriteLine.

  • 초급
  • 2분 분량
  • 실행 가능한 예제 1개
배울 내용
  • Where a C# program starts
  • Printing with Console.WriteLine
  • What using System does
From source to output
  1. 1Program.csYou write the code
  2. 2dotnet buildThe compiler turns it into IL
  3. 3Main()The .NET runtime calls Main
  4. 4Hello, C#!The text appears

How a C# console program runs

모든 C# 콘솔 애플리케이션은 Main 메서드에서 실행을 시작합니다. 이 메서드는 클래스 안에 있으며, 여기서는 Program 클래스입니다. 파일 맨 위의 using System 지시문 덕분에 System.Console처럼 전체 이름을 쓰지 않고도 Console 같은 .NET의 기본 제공 타입을 쓸 수 있습니다.

Main 메서드는 아직 아무 객체도 만들어지지 않은 상태에서 프로그램이 시작하자마자 호출하므로 static으로 선언합니다. Console.WriteLine 문은 화면에 텍스트 한 줄을 출력하고 줄을 바꾸므로 결과는 Hello, C#!입니다.

핵심 포인트

  1. The runtime starts your program by calling Main.
  2. Console.WriteLine prints a line of text and moves to the next line.
  3. using System lets you write Console instead of System.Console.

실행 가능한 C# 예제

C#
코드 실행 →
Program.cs
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, C#!");
    }
}
이 예제의 실행 버튼 만들기 실행 결과
Hello, C#!

디버거로 연습하기

중요한 대입이나 조건에 중단점을 두고 Debug를 눌러 다음 줄로 넘어가기 전에 지역 변수 값을 확인하세요.

챌린지로 연습하기

이 레슨에서 배운 내용으로 실제 문제를 풀어 보세요. 모든 챌린지는 브라우저에서 실행되며 즉시 테스트와 AI 리뷰를 받을 수 있습니다.

모든 챌린지