Why do we assign a string with parenthesis?
eventText.text = ("hello world");
I see that this works also:
eventText.text = "hello world";
Why do we assign a string with parenthesis?
eventText.text = ("hello world");
I see that this works also:
eventText.text = "hello world";
Hi Paolo, welcome to the community
You don’t, very unnecessary in this case.
See also;
thank you for the answer Rob.
Actually my question is because I would like to know what do parentheses mean around a string. What is the difference in putting them or not?
Thank you for your patience.
It doesn’t mean/do anything.
With math you will find times where you need them, but not with strings.
thank you very much!
You’re very welcome
I personally tend to use parentheses more than I need to with strings because its a habit based upon joining multiple things together… eg. Debug.Log(“string text” + variable). But as Rob says, they are completely not needed in your example - they dont hurt, but aren’t needed.
oh great! now I get it! Thank you Rick.
Thank you! So Debug.Log() due to being a method would need the parenthesis if i understand correctly but I had been using something without parenthesis to concatinate like
scoreText.text = "Score: " + score;
I was wondering if there was a difference but both seemed to work so thank you for confirming
Yes, Log
is a method within Debug
, hence the parenthesis, these would be where parameters (if any) are passed in - note this is required for a method, not just because you are concatenating parameters.