I want to create a debug utility function to print a variable's name and value to the console, like this:
float my_variable = 10;
debug_print(my_variable);
And have the output be "my_variable = 10"
How would I be able to do this?
I want to create a debug utility function to print a variable's name and value to the console, like this:
float my_variable = 10;
debug_print(my_variable);
And have the output be "my_variable = 10"
How would I be able to do this?
You can use the nameof
expression to get the name of a variable (though you have to pass the variable to it, so not sure how that's helpful since you already know the name), and then show the value:
Debug.Print($"{nameof(my_variable)} = {my_variable}");
Which is the same as:
Debug.Print($"my_variable = {my_variable}");
However, if this were put into a method, it would output the name of the method argument variable, not the name of the variable you pass in.