Kiki Devlog

출력문 본문

Language/C #

출력문

kimkiki 2022. 6. 30. 10:29
728x90

Console.WriteLine() / Console.Write()

이 두 함수는 unity engine에서는 아무 일도 하지 않음. (unity는 custom console system을 사용하기 때문) 그러니까 UnityEngine.Debug.Log /  LogError / LogWarning 등을 사용하자 

- 두 함수의 차이는 WriteLine 은 새로운 라인에 출력한다는 점이다.

   ( c++의 "\n", endl 과 같은 역할. Write() 에서 줄바꿈 기능이 추가됨. 

 

[참고]

Why doesn't Console.WriteLine work in MonoDevelop since it's written in C#? - Unity Answers

Difference between Console.Write and Console.WriteLine in C# - GeeksforGeeks=

 

Debug.Log() 

: 디버그에서 실행할 때만 기록. (릴리즈 된 게임에서는 실행되지 않음)

(Console.WriteLine 은 디버그 또는 릴리스에서 표준 출력 스트림에 쓴다. Debug.WriteLine  Listeners 컬렉션 의 추적 수신기에 기록 하지만 디버그에서 실행할 때만 기록됨 . 응용 프로그램이 릴리스 구성에서 컴파일 될 때 Debug 요소는 코드로 컴파일되지 않는다.)

 

[참고]

.net - What's the difference between Console.WriteLine() vs Debug.WriteLine()? - Stack Overflow

 

 

사용 예시

using System;
// Console.WriteLine 과 Console.Write를 사용하기 위함
// 아니면 System.Console.WriteLine으로 사용가능.

Console.WriteLine("Hello World!");
Console.Write(("Hello World!");

Debug.Log(("Hello World!");

 

Comments