A Quest of Style


i am starting to do some serious programming in C# and am wondering about standards for coding. I have read numerious tutorials and papers about various aspect of C# and no two seem to follow a standard. Any i just missing something? I am the only programmer at my work so there are no standards in place to follow.

Question is there anywhere that has set any standards for C# programming in terms of syntax, naming conventions, function positioning in classes, commenting etc.

Or can someone offer some advice.

I know this may seem trival but everything i got taught at uni/work drilled into me about standards. Please Help.
Who is Participating?
KelmenConnect With a Mentor Commented:
Since you 1st into the realm of "coding style", advise you simply pick one to kick off.

Just pick the M$ .NET approach.

It take years of experience to grow one's "coding style". It's practically a personal preference/taste/religious stuffs.

While many stated avoid hungarian or FxCop, I still adopted it.

Look from your/company purpose on this styling. Is it mean for biz/sale purpose or practical development?

If for biz/sales/ISO-whatever, adopt a well-know industry standard, of at least from a well known vendor standard (like M$).

If its for practical development purpose, then this will depend on many factors (the senior people over there, what language been adopted in past)

Since you are the 1st and foremost in this part, pick one that suid your taste, mix-and-match some.

Do remember, its "styling", just like fashion, mean you can change/enhance it later on.
Here's a convention that much of Microsoft has supposedly adopted, called Hungarian Notation (there is a lot on the web about this):

Timbo87Connect With a Mentor Commented:
That article is pre-.NET and actually, I believe Microsoft now discourages Hungarian notation in .NET.

Here are Microsoft's .NET Naming Guidelines:
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

It is true that Microsoft discourages Hungarian notation in .NET because the IDE can tell you all about your variables when you do a "mouse over" the variable...  
I still think it is worth using so I do, who want to do a "mouse over" when they could just look at it.
gregasmConnect With a Mentor Commented:
Have you ever heard of FxCop? It enforces coding style and conventions, as well as encapsulating best practices. It has an extensible architecture to allow you to add and enforce your own rules.

You can get FxCop here:

Intro to FxCop here:

And here is a great article on how to extend the FxCop rules engine:
somnaticConnect With a Mentor Commented:
@gillgates ..

this mouse over works without the hungarian notation just as well ..

hungarian notation is from the C age ... with features such as you mentioned there is no need for hungarian notation anymore
I just read an article .. but can't remember where ..

the only convention I follow is:
* variableNames start with a lower case letter
* MethodNames start with an upper case letter
* WordsAreSeparatedBy upper case letters
I do mostly what somnatic does... but I also append b for booleans and i for ints.... it's handy to know which variables are flags, and which numeric variables have a decimal.  Also, I have a convention for naming my controls, like btnButton, and txtTextBox, just so I can tell at a glance what control I'm looking at (in the code).


 I was saying who wants to do a mouse over when you can just look at it.

I do the following


I follow similar naming conventions for other variables that I have not listed.
cossy74Author Commented:
thanks for your input.
I understand what is being said.
What about Functions/Methods, Class naming. I followed some Microsoft examples and they list the functions in the code alphabetically, show thius be followed? Do i seperate Data and UI completely?
cossy74Author Commented:

Do i comment functions outside/before or inside the function code.
for example:

/// <summary>
/// Function: PopulateProductList
/// Description:
/// Function's purpose, Special Notes etc
/// </summary>
private void Function()
{ }

private void Function()
/// <summary>
/// Function: PopulateProductList
/// Description:
/// Function's purpose, Special Notes etc
/// </summary>
cossy74, did you take a look at FxCop from the links I posted above?

FxCop is developed in house by microsoft and it is a tool to enforce the best practices, as defined by microsoft. I think it is the best way to learn of and practice c# style.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.