I have some intialized Property/Fields that are “constant” and I want to know which one of the following line is the best to use :
public static Color MyColor { get { return Color.Red; } }public static readonly Color MyOtherColor = Color.Red;
Is there some runtime differences after (lazy)initialization ?
Are the performance usages differents ?
The Field usage guidelines recommend using public static read-only fields for predefined object instances. For example:
In your case, I’d probably use a property:
UPDATE
The guidelines linked above (which use Color as an example) are for .NET 1.1 and have possibly evolved. Personally I don’t think you can go wrong by using a property. .NET 4.0 Field Guidelines are similar, but use
DateTime.MaxValueandDateTime.MinValueas examples of predefined object instances.