Not following the C# naming convention for private field names?

My IDE constantly shouts at me that I should not be using private PlayerControls playerControls;, but rather should use private PlayerControls _playerControls;.

I am not committed to using it or not using it, but I notice the convention of using underscores isn’t followed in the course. I guess I’m just wondering if it would be better for me to follow the convention for C# coding in general, or is this a convention that is widely ignored, in Unity or other C# coding projects?

The underscore convention is one I use myself, but conventions are just conventions and can be whatever you want - it’s for consistency an readability. You should decide which you want to use and stick to it. Using an underscore when the course does not will make no difference to the game. All my course projects use the underscore convention because this is what I’m used to and use all the time.

I don’t know which IDE you use but if you are using Visual Studio, you should be able to configure your naming convention in the options. Then it may perhaps stop shouting at you

1 Like

I am using Rider and I can easily turn off the annoying nagging as you suggest.

I was just wondering if leaving off the underscores would be learning a bad habit for future C# development projects, but from what I’ve read it doesn’t seem like a big deal. As you said, probably should just pick one method and stick with it.

Thanks!

It is not a bad habit. Some teams may require you to use underscores, while others may not. I have been fortunate enough to be the one that make those decisions, so I can stick to what I want (and close to, but not exactly, the C# conventions). It just depends on the team you’re on. If you work by yourself, you make the rules. As long as it’s consistent and does not cause you confusion

1 Like

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

Privacy & Terms