Wednesday, 4 January 2012

Constants

Pascal Case. The use of SCREAMING_CAPS is discouraged. This is a large change from earlier conventions. Most developers now realize that in using SCREAMING_CAPS they betray more implementation than is necessary. A large portion of the .NET Framework Design Guidelines is dedicated to this discussion.
Example:
Here is an example of a class that uses all of these naming conventions combined.
using System;
namespace MyExampleNamespace
{
public class Customer : IDisposable
{
private string _customerName;
public string CustomerName
{
get
{
return _customerName;
}
set
{
_customerName = value;
_lastUpdated = DateTime.Now;
}
}
private DateTime _lastUpdated;
public DateTime LastUpdated
{
get
{
return _lastUpdated;
}
private set
{
_lastUpdated = value;
}
}
public void UpdateCustomer(string newName)
{
if( !newName.Equals(customerName))
{
CustomerName = newName;
}
}
public void Dispose()
{
//Do nothing
}
}
}