Is "this" keyword pointing parameters or variables?

Greetings, hello!
It’s not clear to understand for a beginner. _coordinates would be better to explain maybe.

Is this matching correct? →

Yes, that’s correct. C# convention usually has a capital letter for public variables, and then camelCase for the function or private variables. This way, you can simply do: Coordinates = coordinates, and it’s perfectly clear which is which if you set up all your code this way.

Some people in the earlier days of Unity used underscores (you’ll see it in a lot of the older tutorials especially) a technique they borrowed from C or C++ I believe, but IMO it looks messy. I’ve noticed that gamedev TV has also transitioned to the method I describe above, though some of their earlier tutorials / courses may not do this.

1 Like

Thanks a lot for your answer and extra information. :+1:t2:

I didn’t know that capital letter for public variables. I thought we use capital letters or camel case depends on method or variable. But now, it seems redundant of course. Why we need to seperate method and variable? This is already obvious lol. Public / private differentiation is more important just as this example.

They might have borrowed it from the official C# coding convention.

1 Like

Ah - interesting. I have seen people moving away from the underscore in c# in recent examples and books - but I suppose it is also a preference thing.

There also seems to be some debate and different uses in official examples from Microsoft. Personally I find it cluttering but that may just be me!

Yes, it’s definitively a matter of personal preference. If you saw my very old code examples from a couple of years ago, you would see that I followed the convention as well. However, it’s not common in the Unity community, which is why I don’t use it anymore. Maybe it makes sense in other C# applications where working with different concepts which you want to be able to tell apart at first glance. That could especially make sense in a team. However, I agree with you when it comes to Unity. The code starts looking cluttered fairly quickly.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms