언어/C#

CS5001: Program does not contain a static 'Main' method suitable for an entry point

SharpSteamedBread 2026. 1. 2. 11:46

유니티 공부를 하다가 생 C# 공부를 하려니까 익숙하지 않은 게 있다. C#에서는 진입점인 Main 함수가 무조건 static이어야 한다는 점이다. 유니티에서 Start와 Update 등의 이벤트 함수에 static를 되도록 사용하지 않는 것과는 대조적이다.

Main 함수가 static이 아니라면 아래와 같은 오류가 뜬다.

 

그런데 또 중요한 점은, Main 함수에서 호출할 함수도 static이어야 한다는 것이다.

그러니까 Main 함수는 항상 클래스 안에 포함되어야 하며, Main 함수랑 호출될 다른 함수는 static을 써줘야 하는 것 같다. 찾아보면 같은 의문점을 가진 사람들이 많은 것 같다. 한번 검색해서 확인해 보자.

https://stackoverflow.com/questions/11332494/why-should-the-main-method-be-static

 

Why should the Main() method be static?

I tried to create public void Main() in C#; it says no static void Main found. What exactly does it mean for Main to be static? I know the code works fine for public static void Main(). But why d...

stackoverflow.com

 

+ C#이 객체지향을 따르지만, Main 함수가 객체 없이 사용될 수 있다고 하여 객체지향에 어긋나는 건 아니다. 더 찾아봐야겠다...

'언어 > C#' 카테고리의 다른 글

[DateTime] DateTime의 불변성과 대입 연산자  (0) 2026.02.23
랜덤값 출력(Random 클래스)  (0) 2026.01.02