{"id":13429671,"url":"https://github.com/kodecocodes/c-sharp-style-guide","last_synced_at":"2025-10-04T08:15:09.139Z","repository":{"id":34099163,"uuid":"37925131","full_name":"kodecocodes/c-sharp-style-guide","owner":"kodecocodes","description":"C# Style Guide for Game Tech tutorials","archived":false,"fork":false,"pushed_at":"2023-02-03T06:55:34.000Z","size":38,"stargazers_count":499,"open_issues_count":3,"forks_count":111,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-03-14T00:01:46.637Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kodecocodes.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-23T14:48:16.000Z","updated_at":"2025-03-02T11:23:16.000Z","dependencies_parsed_at":"2023-02-18T04:10:19.269Z","dependency_job_id":null,"html_url":"https://github.com/kodecocodes/c-sharp-style-guide","commit_stats":null,"previous_names":["raywenderlich/c-sharp-style-guide"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fc-sharp-style-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fc-sharp-style-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fc-sharp-style-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fc-sharp-style-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodecocodes","download_url":"https://codeload.github.com/kodecocodes/c-sharp-style-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822310,"owners_count":20353496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:43.548Z","updated_at":"2025-10-04T08:15:04.105Z","avatar_url":"https://github.com/kodecocodes.png","language":null,"funding_links":[],"categories":["Programming Languages"],"sub_categories":["C#"],"readme":"## Table of Contents\n\n- [The Official kodeco.com C# Style Guide](#the-official-kodecocom-c-style-guide)\n  - [Inspiration](#inspiration)\n  - [Nomenclature](#nomenclature)\n    - [Namespaces](#namespaces)\n    - [Classes \u0026 Interfaces](#classes--interfaces)\n    - [Methods](#methods)\n    - [Fields](#fields)\n    - [Properties](#properties)\n    - [Parameters](#parameters)\n    - [Actions](#actions)\n    - [Misc](#misc)\n  - [Declarations](#declarations)\n    - [Access Level Modifiers](#access-level-modifiers)\n    - [Fields \u0026 Variables](#fields--variables)\n    - [Classes](#classes)\n    - [Interfaces](#interfaces)\n  - [Spacing](#spacing)\n    - [Indentation](#indentation)\n      - [Blocks](#blocks)\n      - [Line Wraps](#line-wraps)\n    - [Line Length](#line-length)\n    - [Vertical Spacing](#vertical-spacing)\n  - [Brace Style](#brace-style)\n  - [Switch Statements](#switch-statements)\n  - [Language](#language)\n  - [Copyright Statement](#copyright-statement)\n  - [Smiley Face](#smiley-face)\n  - [Credits](#credits)\n\n# The Official Kodeco C# Style Guide\n\nThis style guide is different from others you may find, because the focus is\ncentered on readability for print and the web. We created this style guide to\nkeep the code in our tutorials consistent.  \n\nOur overarching goals are **conciseness**, **readability** and **simplicity**. Also, this guide is written to keep **Unity** in mind. \n\n## Inspiration\n\nThis style guide is based on C# and Unity conventions. \n\n\n\n\n## Nomenclature\n\nOn the whole, naming should follow C# standards.\n\n### Namespaces\n\nNamespaces are all **PascalCase**, multiple words concatenated together, without hyphens ( - ) or underscores ( \\_ ). The exception to this rule are acronyms like GUI or HUD, which can be uppercase:\n\n**AVOID**:\n\n```csharp\ncom.kodeco.fpsgame.hud.healthbar\n```\n\n**PREFER**:\n\n```csharp\nKodeco.FPSGame.HUD.Healthbar\n```\n\n### Classes \u0026 Interfaces\n\nClasses and interfaces are written in **PascalCase**. For example `RadialSlider`. \n\n### Methods\n\nMethods are written in **PascalCase**. For example `DoSomething()`. \n\n### Fields\n\nAll non-static fields are written **camelCase**. Per Unity convention, this includes **public fields** as well.\n\nFor example:\n\n```csharp\npublic class MyClass \n{\n    public int publicField;\n    int packagePrivate;\n    private int myPrivate;\n    protected int myProtected;\n}\n```\n\n**AVOID:**\n\n```csharp\nprivate int _myPrivateVariable\n```\n\n**PREFER:**\n\n```csharp\nprivate int myPrivateVariable\n```\n\nStatic fields are the exception and should be written in **PascalCase**:\n\n```csharp\npublic static int TheAnswer = 42;\n```\n### Properties\n\nAll properties are written in **PascalCase**. For example:\n\n```csharp\npublic int PageNumber \n{\n    get { return pageNumber; }\n    set { pageNumber = value; }\n}\n```\n\n### Parameters\n\nParameters are written in **camelCase**.\n\n**AVOID:**\n\n```csharp\nvoid DoSomething(Vector3 Location)\n```\n\n**PREFER:**\n\n```csharp\nvoid DoSomething(Vector3 location)\n```\n\nSingle character values are to be avoided except for temporary looping variables.\n\n### Actions\n\nActions are written in **PascalCase**. For example:\n\n```csharp\npublic event Action\u003cint\u003e ValueChanged;\n```\n\n### Misc\n\nIn code, acronyms should be treated as words. For example:\n\n**AVOID:**\n\n```csharp\nXMLHTTPRequest\nString URL\nfindPostByID\n```  \n\n**PREFER:**\n\n```csharp\nXmlHttpRequest\nString url\nfindPostById\n```\n\n## Declarations\n\n### Access Level Modifiers\n\nAccess level modifiers should be explicitly defined for classes, methods and member variables.\n\n### Fields \u0026 Variables\n\nPrefer single declaration per line.\n\n**AVOID:**\n\n```csharp\nstring username, twitterHandle;\n```\n\n**PREFER:**\n\n```csharp\nstring username;\nstring twitterHandle;\n```\n\n### Classes\n\nExactly one class per source file, although inner classes are encouraged where scoping appropriate.\n\n### Interfaces\n\nAll interfaces should be prefaced with the letter **I**. \n\n**AVOID:**\n\n```csharp\nRadialSlider\n```\n\n**PREFER:**\n\n```csharp\nIRadialSlider\n```\n\n## Spacing\n\nSpacing is especially important in kodeco.com code, as code needs to be easily readable as part of the tutorial. \n\n### Indentation\n\nIndentation should be done using **spaces** — never tabs.  \n\n#### Blocks\n\nIndentation for blocks uses **4 spaces** for optimal readability:\n\n**AVOID:**\n\n```csharp\nfor (int i = 0; i \u003c 10; i++) \n{\n  Debug.Log(\"index=\" + i);\n}\n```\n\n**PREFER:**\n\n```csharp\nfor (int i = 0; i \u003c 10; i++) \n{\n    Debug.Log(\"index=\" + i);\n}\n```\n\n#### Line Wraps\n\nIndentation for line wraps should use **4 spaces** (not the default 8):\n\n**AVOID:**\n\n```csharp\nCoolUiWidget widget =\n        someIncrediblyLongExpression(that, reallyWouldNotFit, on, aSingle, line);\n```\n\n**PREFER:**\n\n```csharp\nCoolUiWidget widget =\n    someIncrediblyLongExpression(that, reallyWouldNotFit, on, aSingle, line);\n```\n\n### Line Length\n\nLines should be no longer than **100** characters long.\n\n### Vertical Spacing\n\nThere should be exactly one blank line between methods to aid in visual clarity \nand organization. Whitespace within methods should separate functionality, but \nhaving too many sections in a method often means you should refactor into\nseveral methods.\n\n\n## Brace Style\n\nAll braces get their own line as it is a C# convention:\n\n**AVOID:**\n\n```csharp\nclass MyClass {\n    void DoSomething() {\n        if (someTest) {\n          // ...\n        } else {\n          // ...\n        }\n    }\n}\n```\n\n**PREFER:**\n\n```csharp\nclass MyClass\n{\n    void DoSomething()\n    {\n        if (someTest)\n        {\n          // ...\n        }\n        else\n        {\n          // ...\n        }\n    }\n}\n```\n\nConditional statements are always required to be enclosed with braces,\nirrespective of the number of lines required.\n\n**AVOID:**\n\n```csharp\nif (someTest)\n    doSomething();  \n\nif (someTest) doSomethingElse();\n```\n\n**PREFER:**\n\n```csharp\nif (someTest) \n{\n    DoSomething();\n}  \n\nif (someTest)\n{\n    DoSomethingElse();\n}\n```\n## Switch Statements\n\nSwitch-statements come with `default` case by default (heh). If the `default` case is never reached, be sure to remove it.\n\n**AVOID:**  \n  \n```csharp\nswitch (variable) \n{\n    case 1:\n        break;\n    case 2:\n        break;\n    default:\n        break;\n}\n```\n\n**PREFER:**  \n  \n```csharp\nswitch (variable) \n{\n    case 1:\n        break;\n    case 2:\n        break;\n}\n```\n\n## Language\n\nUse US English spelling.\n\n**AVOID:**\n\n```csharp\nstring colour = \"red\";\n```\n\n**PREFER:**\n\n```csharp\nstring color = \"red\";\n```\n\nThe exception here is `MonoBehaviour` as that's what the class is actually called.\n\n## Copyright Statement\n\nThe following copyright statement should be included at the top of every source file:\n\n    /*\n     * Copyright (c) 2023 Kodeco Inc.\n     * \n     * Permission is hereby granted, free of charge, to any person obtaining a copy\n     * of this software and associated documentation files (the \"Software\"), to deal\n     * in the Software without restriction, including without limitation the rights\n     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n     * copies of the Software, and to permit persons to whom the Software is\n     * furnished to do so, subject to the following conditions:\n     * \n     * The above copyright notice and this permission notice shall be included in\n     * all copies or substantial portions of the Software.\n     *\n     * Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, \n     * distribute, sublicense, create a derivative work, and/or sell copies of the \n     * Software in any work that is designed, intended, or marketed for pedagogical or \n     * instructional purposes related to programming, coding, application development, \n     * or information technology.  Permission for such use, copying, modification,\n     * merger, publication, distribution, sublicensing, creation of derivative works, \n     * or sale is expressly withheld.\n     *    \n     * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n     * THE SOFTWARE.\n     */\n\nIn this repository, copy the **ScripTemplates** folder into your own Unity **Assets** folder. This way the header above will be included in new scripts.\n\n\u003e **NOTE**: You may need to close and reopen Unity in order for it to start picking up the template.\n\n## Smiley Face\n\nSmiley faces are prominent style feature of the kodeco.com site!\nIt's important to have the correct smile signifying the immense amount of happiness and excitement for the coding topic. The closing square bracket ] is used because it represents the largest smile able to be captured using ASCII art. A closing parenthesis (\"**:)**\") creates a half-hearted smile, and thus is not preferred.\n\n**AVOID**:\n\n:)\n\n**PREFER**:\n\n:]  \n  \n\u003e **NOTE**: Do not use smileys in your scripts.\n\n## Credits\n\nThis style guide is a collaborative effort from the most stylish\nkodeco.com team members:\n\n- [Darryl Bayliss](https://github.com/DarrylBayliss)\n- [Sam Davies](https://github.com/sammyd)\n- [Mic Pringle](https://github.com/micpringle)\n- [Brian Moakley](https://github.com/VegetarianZombie)\n- [Ray Wenderlich](https://github.com/rwenderlich)\n- [Eric Van de Kerckhove](https://github.com/BlackDragonBE)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodecocodes%2Fc-sharp-style-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodecocodes%2Fc-sharp-style-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodecocodes%2Fc-sharp-style-guide/lists"}