I have a special dislike for walls of characters in code and I try to get rid of it whenever possible, as I mentioned in this other post. The keyword private in C# is another one that bugs me. Take the following code:

What do I see there?

I like this way better:

Every class member is private by default in C#, as it should be. We should always keep public members to a minimum, so I rather be explicit as to what’s NOT private in my classes. By removing the unnecessary private modifier keyword, I clean up my code. The less garbage there is around the code, the easiest it is for anybody to read and understand it.

For ReSharper users out there: you can set the tool so that it’ll remove “private” modifiers when you run Code Cleanup.

 

3 responses to “The “private” keyword in C#: I get rid of it!”

  1. […] I’ve mentioned before (here, here, and here, at least), I’m very specific as to how much stuff I want to see on my screen as I’m […]

  2. […] The “private” keyword in C#: I get rid of it! […]

  3. […] I prefer NOT to see the “private” keyword in C# code. As a quick update to that post, here’s how to set up JetBrains Rider to not add “private” when it creates code, and also to remove it when using its “Reformat and Cleanup Code” feature: […]

Leave a Reply

Trending

Discover more from Claudio Lassala's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading