C Sharp Cheat Sheet



  1. C# Syntax Cheat Sheet
  2. C Sharp Cheat Sheet Pdf
  3. C Sharp Cheat Sheet Pdf

C# provides you with access to a phenomenal array of programming options. Use this cheat sheet to help you get the job done faster and easier when using C# as your development solution of choice.

The XML documentation tags of C# are described very well in the MSDN. However, the article does not explain how the contained phrases and sentences should be written. This article tries to fill this gap by providing rules and some sample phrases.

I recommend using StyleCop because its rules enforce some of the XML documentation recommendations from this article. Also check out the Visual Studio extension GhostDoc which automates and simplifies the writing of XML documentation.

Sharp

Cheat Sheet: Best practices for writing XML documentation in C# Published 2015-03-11 Updated 2018-10-04 The XML documentation tags of C# are described very well in the MSDN. C# Basics Cheat Sheet (1 of 4) begincodingnow.com. Introduction to C#. The C# language was developed by Microsoft for the.NET framework. C# is a completely-rewritten language based on C Language and C Language. It is a general-purpose, object-oriented, type-safe platform-neutral language that works with the.NET Framework. Visual Studio (VS). Find color c, the average between colors c1, c2. C, c1, c2 are strings of hex color codes: 7 chars, beginning with a number sign #. Assume linear computations, ignore gamma corrections. Using System.Drawing.

General

  • All XML documentation phrases should end with a period (.) and no blank:

  • The summary tags should only contain the most important information. For further details use an additional remarks tag. To avoid having too much documentation in your source code files, read this article which explains how to “outsource” documentation to an external file.

Classes

  • Each class should have a summary tag describing its responsibility. The summary often starts with “Represents …“ or “Provides …“ but other forms also exist:

Sheet

Constructors

  • The documentation of a constructor should be in the form “Initializes a new instance of the <see cref=”TYPENAME”/> class.”</see>:

Sheet

Properties

  • The summary of a property should start with “Gets or sets …“ if it is fully accessible, with “Gets …“ when the property is read-only, and with “Sets …“ if it is write-only:

  • Note: According to the very recommended book Framework Design Guidelines, write-only properties should not be used at all.

  • A property of type bool should start with “Gets or sets a value indicating whether …“:

Events

  • Each event should have a summary tag which starts with the words “Occurs when …“:

  • Note: Events should be named with a verb or verb phrase. Use the present and past tenses to express if the delegate is invoked before (e.g. Closing) or after (e.g. Closed) a particular event.

Methods

  • Like the method name itself, the text in the summary tag should start with a verb:

Method parameters

  • Each method parameter should have a corresponding param tag containing a description of the parameter:

  • If the parameter is an enum or of type bool consider starting the description with “Specifies …“ (enum) or “Specifies whether …“ (bool)

  • Note: According to Clean Code you should not use bool method parameters.

Method return value

C# Syntax Cheat Sheet

  • If the method returns a value, you should add a returns tag which contains a description of the returned object:

  • If the returned value is of type bool the documentation should be in the form true if CONDITION; otherwise, false.”:

Exceptions

Sheet
  • The exception exception tag contains the reason why the exception occurred:

  • Tip: Have a look at Exceptional for ReSharper which greatly helps creating XML documentation for exceptions.

Final words

The rules in this articles are used in StyleCop and in the .NET Framework, therefore I think using them is best practice. Because it looks more clean to me, I write the opening tag, content and closing tag on a single line. Of course you can write them on multiple lines as proposed by the Visual Studio templates. For the generated XML documentation file it does not matter what style you are using.

C Sharp Cheat Sheet

What do you think about the described XML documentation rules? Are some rules missing in this list?

C Sharp Cheat Sheet Pdf


Rico Suter SOFTWARE ENGINEERING EDIT
Best PracticesXML Documentation.NETC#Cheat SheetClean CodeCoding GuidelinesDocumentation

C Sharp Cheat Sheet Pdf

Please enable JavaScript to view the comments powered by Disqus.