CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: enum base types

Threaded View

  1. #1
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    enum base types

    I'm trying to find you what is the 'point' of specifying a base type in an enum? What is the benefit of using...
    Code:
    enum State : int  // note the 'int'
    {
    	Initialise = -1,
    	Process = 0,
    	Finalise = 1
    }
    over...
    Code:
    enum State
    {
    	Initialise = -1,
    	Process = 0,
    	Finalise = 1
    }
    One incorrect assumption that I made was to assume you would be able to do...
    Code:
    Stage currentStage = Stage.Initialise;
    int databaseField = currentStage;  // ultimately a field in a DataTable of type SqlDbType.Int
    but it seems you still need to cast...
    Code:
    Stage currentStage = Stage.Initialise;
    int databaseField = (int)currentStage;
    So what is the reason for specifying a base type?

    I do realise the 'int' is the default, I'm just talking in general. All I can think of is compiler optimisation or early binding of errors maybe...
    Last edited by rliq; December 10th, 2008 at 06:34 PM.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured