Home c# How to display a C # object in the Unity console

How to display a C # object in the Unity console




PHP has a convenient var_dump function, I haven’t been studying C # for a long time, the search methods didn’t work. Is there something similar here?

Console.Write () is not what you want. There Debug.Log () , although I don’t know if there is a difference

Answer 1

Here’s a method that will do what you want.
I did not check the code, I wrote from my head, so there may be errors.

Make it as an extension to the Debug class and you will be happy.
If bugs have crept in in the code, fix it keeping the logic.

public static void Logissimo (object obj)
    string rez = typeof (item) .ToString ();
    if (obj is IEnumerable)
      rez + = "= & gt; {";
      int count = 0;
      for (var item in array)
        Debug.Log ($ "[{count ++}] {typeof (item)} = & gt; {item}; \ r \ n");
      rez + = "}";
      rez + = $ "= & gt; {obj}";
    Debug.Log (rez);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions