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

Threaded View

  1. #4
    Join Date
    May 2007
    Posts
    1,546

    Re: Use enum from another class?

    What error are you getting? I assume you just coded your method incorrectly and it's throwing an error saying you can't convert from enum to int? Your method signature should look like this:

    Code:
    void SetContainerType(class1.ContainterTypes container)
    {
        if(container == class1.ContainerTypes.CT_XML)
            ConvertToXml();
    }
    I also wouldn't recommend casting your enums to and from their values for internal code, for example this is bad:

    Code:
    // This is bad
    switch((int) myEnum)
    {
         case 0:
            break;
    
        case 1:
            break;
    
        case 2:
            break;
    }
    
    
    // This is good
    switch(myEnum)
    {
         case MyEnum.Red:
            break;
    
        case MyEnum.Blue:
            break;
    
        case MyEnum.Green:
            break;
    }
    Last edited by Mutant_Fruit; September 29th, 2007 at 12:56 PM.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

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