Help understanding case sensitivity

Hi all,

My biggest, albeit minor, struggle with Unity/C# so far is case sensitivity. I do have coding/scripting experience, but mostly in languages that are not case sensitive, or in which it’s a well-adopted custom to stick to a single case. Almost every time I’ve had a problem with my own code in this course, it’s seemed to be because I’ve got a capital and lower-case mixed up.

So I wondered, could anyone please point me to some explanation to the general case standards used in C# or Unity? It might be that I just don’t know enough of the names of types of things, so a guide would be helpful for me.

For example, in this lecture:

Instantiate(towerPrefab, transform.position, Quaternion.identity);

We’ve got Instantiate with a capital - title case I guess. Built in method though, I can hopefully get that they start with a capital. But then we’ve got the towerPrefab variable we created in Camel Case. Ok so I can sort of follow that built-in methods use title or Pascal case and user-defined items use Camel. But after that, we’ve got ‘transform’ in all lower case, but ‘Quaternion’ is in title/Pascal case. I would have expected them to be the same and if I wasn’t following along I would 100% have put them both the same case so got one of them wrong.

TL;DR on that last bit - in that line ‘transform’ is lower case and ‘Quaternion’ is pascal case - please help me understand why.

Any pointers would be appreciated!

Thanks

https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions

Method followed by 3 parameters in parenthesis.

A method name. Always capitalize a method name in C#. Pascal case.

Pretty much.

Yep, it’s a reference variable (camel case) with another user defined variable (camel case).

Yep, Quaternion is a class (Pascal case) and identity would be a static user definited variable (Camel case).

They’re different things. It’s so you can see what they are without needing to go digging too far. When you know what they are, that helps you understand how you’re supposed to apply/access them.

1 Like

Thank you very much, that’s very helpful! I looked in the Unity docs but didn’t find anything particularly helpful. I’ll have a read through of the Microsoft page.

Heh. I’ve made it on to the “Debugging Tools” lecture where he creates a public property for the internal variable isPlaceable, and notes the convention is to write it in Pascal Case: IsPlaceable. The confusion for me!! I will get used to this, I will… :laughing:

Yeah, you’ll get used to it.

The why will make more sense when you get to inheritance, encapsulation and Interfaces. C# is very much a more refined language than most others. At least, it is in my mind.

1 Like