Choosing Between Enumerations and Boolean Parameters

The following guidelines help you determine whether a parameter's type should be an enumeration or Boolean value.

Do use enumerations if a member would otherwise have two or more Boolean parameters.

Enumerations add significant readability to member signatures. Consider the following method call:

Type.GetType("Contoso.Controls.Array", True, False)
Type.GetType("Contoso.Controls.Array", true, false);

Type::GetType("Contoso.Controls.Array", true, false);

Calls like this are very difficult to understand without checking the documentation or adding code comments. It is much easier to read a call that uses enumeration values in place of multiple Boolean values as demonstrated in the following code example.

BetterType.GetType("Contoso.Controls.Array", _
    ErrorOptions.ThrowOnError, _
    CasingOptions.CaseInsensitive)
BetterType.GetType("Contoso.Controls.Array", 
    ErrorOptions.ThrowOnError, 
    CasingOptions.CaseInsensitive);

BetterType::GetType("Contoso.Controls.Array",
ErrorOptions::ThrowOnError,
CasingOptions::CaseInsensitive);

Do not use Booleans unless you are absolutely sure there will never be a need for more than two values.

Enumerations allow for adding values in later versions, however, adding values to enumerations can introduce compatibility issues. For additional information, see Adding Values to Enumerations.

Portions Copyright 2005 Microsoft Corporation. All rights reserved.

Portions Copyright Addison-Wesley Corporation. All rights reserved.

For more information on design guidelines, see the "Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries" book by Krzysztof Cwalina and Brad Abrams, published by Addison-Wesley, 2005.

See Also

Concepts

Parameter Design

Other Resources

Member Design Guidelines

Design Guidelines for Developing Class Libraries