-
Notifications
You must be signed in to change notification settings - Fork 1
C# Style
-
Maintain indentation standards. This is crucial to readable code. Always use spaces instead of tabs. Default setting is 4 spaces, and this should be kept if possible, so as to remain compatible with other teams. However, some houses have adopted the 2-space standard because their code-base was created in the days of smaller screens and before people learned to write proper functions. (cref. “Functions should do one thing”)
-
In C#, curly braces should be on a new line. There are two exceptions:
- Very short object initializers, e.g.
var message = new Literal { ID = "Message" };
- Property declarations, whether automatic properties or simple getters/setters direct to private members.
- Very short object initializers, e.g.
-
Curly braces for delegates, collections, or object initializers should be indented 4 spaces (ME). Other specifications say differently, but following those specifications would require reformatting your indents every time you change a type or variable name, or even switch to
var
instead of explicit type declarations.var sqlParameters = new[] { new SqlParameter("@accountId", accountId), new SqlParameter("@loginSource", ipAddress), }; using (var sqlCommand = new DataAccessObject()) { sqlCommand.FillObject(sqlParameters, delegate(IDataReader reader) { while (reader.Read()) { // Todo: Put code here. } }); }
-
Omit parenthesis when using object initializers, e.g.
var message = new Literal { ID = "Message" };
-
test
Pages in this wiki make use of the following resources throughout
- Martin, R. C., Feathers, M. C., Ottinger, T. R., Langr, J. J., Schuchert, B. L., Grenning, J. W., Wampler, K. D., ... Coplien, J. O. (2011). Clean code: A handbook of agile software craftsmanship. Upper Saddle River [etc.: Prentice Hall.
- Lowy, Juval, (July 2011). “C# Coding Standard: Guidelines and Best Practices.” (Version 2.4) www.idesign.net, © 2011 IDesign Inc.
Resources besides these will be referenced directly where they are cited.