C# Coding Standards
Classes
public class ClientActivity
{
public void ClearStatistics()
{
//...
}
public void CalculateStatistics()
{
//...
}
}
Variables
public class UserLog
{
public void Add(LogEvent logEvent)
{
var itemCount = logEvent.Items.Count;
// ...
}
}
Identifiers
int iCounter;
string strName;
int counter;
string name;
Constants
public const string SHIPPINGTYPE = "DropShip";
public const string ShippingType = "DropShip";
Abbreviations
UserGroup usrGrp;
Assignment empAssignment;
UserGroup userGroup;
Assignment employeeAssignment;
// Exceptions
CustomerId customerId;
XmlDocument xmlDocument;
FtpHelper ftpHelper;
UriPart uriPart;
Abbreviation Casing
HtmlHelper htmlHelper;
FtpTransfer ftpTransfer;
UIControl uiControl;
Underscores
public DateTime client_Appointment;
public TimeSpan time_Left;
public DateTime clientAppointment;
public TimeSpan timeLeft;
// Exception
private DateTime _registrationDate;
Types
String firstName;
Int32 lastIndex;
Boolean isSaved;
string firstName;
int lastIndex;
bool isSaved;
Implicit Types
var stream = File.Create(path);
var customers = new Dictionary();
// Exceptions
int index = 100;
string timeSheet;
bool isCompleted;
Noun Class Names
public class Employee
{ }
public class BusinessLocation
{ }
public class DocumentCollection
{ }
Interfaces
public interface IShape
{ }
public interface IShapeCollection
{ }
public interface IGroupable
{ }
Files
// Located in Task.cs
public partial class Task
{
//...
}
// Located in Task.generated.cs
public partial class Task
{
//...
}
Namespaces
// Examples
namespace Company.Product.Module.SubModule
namespace Product.Module.Component
namespace Product.Layer.Module.Group
Brackets
public class UserLog
{
public void Add(LogEvent logEvent)
{
// ...
}
}
Members
public class Account
{
public static string BankName;
public static decimal Reserves;
public string Number {get; set;}
public DateTime DateOpened {get; set;}
public DateTime DateClosed {get; set;}
public decimal Balance {get; set;}
public Account()
{
// ...
}
}
Enums
public enum Color
{
Red,
Green,
Blue,
Yellow,
Magenta,
Cyan
}
// Exception
[Flags]
public enum Dockings
{
None = 0,
Top = 1,
Right = 2,
Bottom = 4,
Left = 8
}
Enum Types
public enum Direction : long
{
North = 1,
East = 2,
South = 3,
West = 4
}
public enum Direction
{
North,
East,
South,
West
}
Enum Suffix
public enum CoinEnum
{
Penny,
Nickel,
Dime,
Quarter,
Dollar
}
public enum Coin
{
Penny,
Nickel,
Dime,
Quarter,
Dollar
}
Last modified: 21 May 2024