Home > other >  2 lines in the Debug.Log result C#
2 lines in the Debug.Log result C#

Time:10-23

How can I show the Debug.Log in 2 lines (like adding an enter or <br>) in C#?

I have lots of info to show and compare, yet it is not convenient to read it in one line.

Current result: Debug.Log("Pointer:" " " pointerPosX " " pointerPosY " " "target" " " targetPosX " " targetPosY);

Expected result:

Pointer: pointerPosX " " pointerPosY

Target: targetPosX " " " targetPosY

P.S. This is my first question in StackOverflow - so, please, let me know if I did something wrong.

CodePudding user response:

Option 1 (\n):

Debug.Log("Pointer:"   " "   pointerPosX   " "
      pointerPosY   "\n"   "Target:"   " "   targetPosX   " "   targetPosY);

Option 2 (System.Environment.NewLine):

Debug.Log("Pointer:"   " "   pointerPosX   " "   pointerPosY   
System.Environment.NewLine   "Target:"   " "   targetPosX   " "   targetPosY);

Using $ - string interpolation

Option 1:

Debug.Log($"Pointer: {pointerPosX} {pointerPosY}\nTarget: {targetPosX} {targetPosY}");

Option 2:

Debug.Log($"Pointer: {pointerPosX} {pointerPosY}{System.Environment.NewLine}Target: {targetPosX} {targetPosY}");

Difference between "\n" and Environment.NewLine

  • Related