Was this page helpful?

C# Coding Style

    Indentation

    Use 4 spaces, not tabs.

    Variable Naming

    • Camel Case, first letter is lower case
    • No abbreviations
    • Instance fields are prefixed with underscore (_)

    Class, Struct, & Method Naming

    • Camel Case, first letter is upper case
    • Methods are verbs
    • Properties/fields are nouns

    Vertical Whitespace

    • Inside method only when preceeding a comment
    • Inside class declaration Single line between methods, sections

    Blocks

    • Always use Curly braces for blocks, even single line
    • Exception: single line lambdas do not need Curly braces

    TODO & Notes

    // TODO (yourname): Your todo (http://youtrack.developer.mindtouch.com/issue/BUG)
    // (yourname): Your note
    
    Unassigned TODOs
    // TODO (BUG-XXX) Title here (http://youtrack.developer.mindtouch.com/issue/BUG)

    Visual Studio C# Formatting (go to Tools > Options > Text Editor > C#)

        Tabs
            Tab size: 4
            Indent size: 4
            Insert spaces
        Formatting
            Indentation
                Indent block contents: ON
                Indent open and close braces: OFF
                Indent case contents: ON
                Indent case labels: OFF
                Label indentation: PLAE GOTO LABELS ONE INDENT LESS THAN CURRENT
            New lines
                New line options for braces (ALL OFF)
                New line options for keywords (ALL OFF)
                New line options for expressions (ALL OFF)
            Spacing
                Set spacing for methods declarations (ALL OFF)
                Set spacing for method calls (ALL OFF)
                Set other spacing options (ALL OFF)
                Set spacing for brackets (ALL OFF)
                Set spacing for delimiters
                    Insert space after colon for base or interface in type declaration: ON
                    Insert space after comma: ON
                    Insert space after dot: OFF
                    Insert space after semicolon in "for" statement: ON
                    Insert space before colon for base or interface in type declaration: ON
                    Insert space before comma: OFF
                    Insert space before dot: OFF
                    Insert space before semicolon in "for" statement: OF
                Set spacing for operators: INSERT SPACE BEFORE AND AFTER BINARY OPERATORS
            Wrapping
                Leave block on single line: ON
                Leave statement and member declarations on the same line: OFF

    Class Organization

    Organize class members into these categories in this order using these comments, each preceded by a blank line (omit comment when category has no members)
        //--- Constants ---
        //--- Types ---
        //--- Class Fields ---
        //--- Class Constructor ---
        //--- Class Properties ---
        //--- Class Methods ---
        //--- Fields ---
        //--- Constructors ---
        //--- Properties ---
        //--- Methods ---
        //--- Interface Methods ---

    Sort members in each category in this order:
        public
        protected
        protected internal
        internal
        private

    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by