TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  5@106

Synopsis:Use a public static readonly field to define predefined object instances
Language:C#
Severity Level:4
Category:Object lifecycle


Description:

For example, consider a Color class/struct that expresses a certain color internally as red, green, and blue components, and this class has a constructor taking a numeric value, then this class may expose several predefined colors like this.

public struct Color
{
  public static readonly Color Red = new Color(0xFF0000);
  public static readonly Color Black = new Color(0x000000);
  public static readonly Color White = new Color(0xFFFFFF);

  public Color(int rgb)
  {
	  // implementation
  }
}