-
Notifications
You must be signed in to change notification settings - Fork 3
Coding Conventions
André "MG" Wisén edited this page Jan 22, 2019
·
3 revisions
Object Name | Notation |
---|---|
Class name | PascalCase |
Method name | PascalCase |
Method arguments | camelCase |
Function name | PascalCase |
Function arguments | camelCase |
Local variables | camelCase |
public class ClientActivity
{
public void ClearStatistics()
{
//...
}
public void CalculateStatistics()
{
//...
}
}
#### 2. Use meaningful names for variables.<br>The following example uses **seattleCustomers** for customers who are located in Seattle:
```csharp
var seattleCustomers = from cust in customers
where cust.City == "Seattle"
select cust.Name;
Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.
// Correct
UserGroup userGroup;
Assignment employeeAssignment;
// Avoid
UserGroup usrGrp;
Assignment empAssignment;
// Exceptions
CustomerId customerId;
XmlDocument xmlDocument;
FtpHelper ftpHelper;
UriPart uriPart;
HtmlHelper htmlHelper;
FtpTransfer ftpTransfer;
UIControl uiControl;
Exception: You can prefix private static variables with an underscore:
// Correct
public DateTime clientAppointment;
public TimeSpan timeLeft;
// Avoid
public DateTime client_Appointment;
public TimeSpan time_Left;
// Exception (Class field)
private DateTime _registrationDate;
// Correct
public enum Color
{
Red,
Green,
Blue,
Yellow,
Magenta,
Cyan
}
// Exception
[Flags]
public enum Dockings
{
None = 0,
Top = 1,
Right = 2,
Bottom = 4,
Left = 8
}