Appendix C. C# coding conventions

C# coding conventions and guidelines are very different from Java's and take some getting used to if you have been a 100% Java developer so far. [1]

[1] C++ developers should also take note of the new set of guidelines. Even within the C++ community, significant but different naming and casing conventions have sprung up. For example, Windows C++ developers usually prefix strings with psz or lpsz, but Unix C++ developers do not. Some C++ developers also use the Hungarian notation (which is popular in VB programs) but some do not. It would be nice if all C# developers adopted an 'international' convention as documented in the C# Language Specification.

This appendix lists and compares the standard coding conventions of both languages. Bear in mind that conventions and guidelines (unlike specifications) are not mandatory, and can be extended or modified to suit a development team's culture and preferences. Nevertheless, it is highly recommended that you stick to a common convention so that your codes are much more readable outside your project team. Adherence to common practices and guidelines is also good practice in software professionalism.

Table C.1. Common casings/notations used in programming
NameDescriptionExample
Pascal casingThe first letter of each word is capitalized and the first letter of each word in the string also starts with a capital letter – no underscores are used to separate wordsShowWarningMessage GetColor
Camel casingThe first letter of each word is not capitalized but each word in the string starts with a capital letter – no underscores are used to separate wordsshowWarningMessage getColor
All upper caseEvery letter in the string is capitialized – to improve readability, it is common to separate words in the string with an underscoreSHOW_WARNING _MESSAGE GETCOLOR
Hungarian notationVariable names are prefixed with letters that represent the data typeString sMessage char cLetter

Table C.1 gives some common notations/casing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.240