Sign in to follow this  

C# "standard" coding conventions

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello beginner forum, long time no see! I'm currently learning C# and, as I'm starting up, I'd like to pick up good coding conventions habits right away. I noticed that C# code looks much more standarised than C++ (people seem to be using about the same conventions). For exemple, in C++, very few people seems to use the STL coding convention. I'd like to know if there exists an online document which describes the coding convention used in all of the C# classes contained in the System namespace and it's subnamespaces as well as in the Microsoft namespace and it's subnamespaces. If no such thing exists, which coding convention that do you suggest? I hope I'm not saying anything dumb! Thank you! [edit] by "coding conventions", I mean capitalisation and use of m_***, s_***, I***.

Share this post


Link to post
Share on other sites
Mostly I tend to follow the .NET conventions, summarized here (there's also a nice thick Microsoft Press book on the same subject that covers things in more detail, but I wouldn't recommend it unless you have the spare cash as its not really essential.

Share this post


Link to post
Share on other sites
Thanks a lot! I'll have a look at it.

Can I ask another quick question? Can a class be declared private, even if it is not a class-within-a-class, in order to allow only access from classes that are in the same namespace?

Share this post


Link to post
Share on other sites
There is no "namespace only" access specifier in C#.

There is "internal" which means only available to classes in the same assembly. So that companies can put helper functions that are not part of their public client API inside internal only classes, that way the public API of an assembly represents what is meant to be called publicly.

Although in general the main use is to allow component vendors to sell components that use code, you don't want to give complete / direct access to every client (perhaps allowing the selling of different / professional version where they do have such unrestricted access.

Share this post


Link to post
Share on other sites
Thank you Xai.

It wouldn't make much sense to have a namespace-only access specifier on classes because then you could create a class in that namespace with the sole purpose of accessing the "private" class. Anyways, I'm looking into "Internal".

Share this post


Link to post
Share on other sites

This topic is 3857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this