Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Parameter Design
 Choosing Between Enumerations and B...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Developer's Guide
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:

Visual Basic
Type.GetType("Contoso.Controls.Array", True, False)

C#
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.

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

C#
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.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker