If I understand you correctly this basic principle should get you what you want. Important things to note are that the instances are static and can be accessed everywhere, and that the private constructor prevents any other code (barring reflection, you'll never prevent that) creating its own instances of ContactType.
sealed class ContactType
{
public static ContactType Internal { get; } = new ContactType();
public static ContactType External { get; } = new ContactType();
private ContactType()
{
}
}
If you want more code involved in initialising the instances you may want to use a static constructor. This would look something like this:
sealed class ContactType
{
public static ContactType Internal { get; }
public static ContactType External { get; }
private ContactType()
{
}
static ContactType()
{
// More code can fit here if creating ContactType is complicated
Internal = new ContactType();
External = new ContactType();
}
}
The static constructor will run once (right before the class is first used somewhere in your code) and set the static properties.
And here's an implementation that also handles the ToString() functionality:
sealed class ContactType
{
private readonly string contactTypeName;
public static ContactType Internal { get; } = new ContactType("Internal");
public static ContactType External { get; } = new ContactType("External");
private ContactType(string contactTypeName)
{
this.contactTypeName = contactTypeName;
}
public override string ToString()
{
// Note that these two ways of building this string are equivalent.
// You may be more familiar with the old commented out way, but C# 6 added this new interpolation syntax.
// Take your pick between the two, I prefer the interpolation.
//return "Contact of type " + this.ContactTypeName;
return $"Contact of type {this.contactTypeName}";
}
}