❔ C# private methods capitalization convention
What is the official capitalization convention for private methods?
The capitalization convention page (https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions) does not mention private methods explicitly.
However the dotnet runtime repo enforces PascalCase for all methods (https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/coding-style.md number 13)
So what is the official convention?
37 Replies
generally the convention is that all methods are pascal case
to me, prefixing with _ also looks fine
but that's just my opinion
A method?
Generally yeah, but I am asking what the official convention is.
that's the convention
that's what I'm saying
Where can I find it in the Microsoft documentation?
Why do you need some website to say it...?
Because I’d like to comply with official Microsoft guidelines and using the recommended best practices
So why do you need a website to say it
There are no guidelines
There are no "official" conventions
You do whatever you want
Or whatever your team does
There are… as per: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions
Capitalization Conventions - Framework Design Guidelines
Apply capitalization conventions for identifiers, compound words, and common terms. Understand how case sensitivity works in .NET.
No one is gonna put you in jail for not following these
Sure, but that still does not answer my question.
I think they just forgot to mention it there
C# Coding Conventions
Learn about coding conventions in C#. Coding conventions create a consistent look to the code and facilitate copying, changing, and maintaining the code.
they say you should use pascal case for public things, but fail to mention private methods
even tho in all their code they're Pascal Case
It even does mention methods
Methods: PascalCase
open any codebase, they're pascal case
What more could you want
Yep, hence I am asking what the official convention is. Because it’s undocumented.
If it bothers you, you can open an issue on the docs repo
The documentation Anton linked says "When naming
public
members of types, such as [...] local functions, use pascal casing."
Which, while contradictory, lets me assume that private methods are also pascal case
Like, a local function is not a public member by defaulti don't know where it's literally written down, but 99% of c# codebases i've seen use pascal case for all methods
This dude won't even start writing code until literally every convention is laid out and documented
yeah i wouldn't worry about it too much
you can just change it later if you decide you don't like how you're naming things
That’s not the case. But I’d like to know what the official convention is. That’s all 🙂
its PascalCase for all methods.
.NET is open source, you can read the source of the core libs.. its all PascalCase
you can also just do
dotnet new editorconfig
editorconfig is best config
I know I can and I have. But if it’s the official convention then why is it not mentioned in the example on the capitalization convention documentation?
Anyways, I’ve created an issue on the docs repo.
Because noone has ever questioned it, in the last 20 years of C# development 😛
the truth is... nobody looks at or cares about that document. you follow whatever conventions you like. and if those happen to be the .net runtime conventions, which are the most widely used, then you line up with 99% of c# developers already
I don't understand why it needs to be explicitly stated, but I wont be sad if it gets added to the docs either.
Its not like the docs suggest it would be any other way, and everyone except fleksi writes private methods as PascalCase, so its "convention by default"
Because some people I am working with are not satisfied with “but the dotnet runtime repo uses it” so I need an official source from the C# docs stating what the convention is. But yeah I think in general you can’t go wrong with being more explicit with conventions
Hence I opened an issue on the docs repo 🙂
And thats fine, good even.
I agree with you that explicit is better than implicit, but how someone can read that document, the runtime contribution guidelines and all the open source code and say "you know what, its inconclusive!" is.... mindboggling
🤷🏻♂️
but they are official
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.