CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    69

    Post How reset the Existing enum type values

    Dear All,

    I am using enum type in my code, i need to reset the existing enum type. how can i achieve this.

    public enum shape { line = 1, Rectangle, Circle };

    here,

    line=1,

    Rectangle=2,

    Circle=3

    I need to reset this as ,

    line=0,

    Rectangle=0,

    Circle=0

    How can i reset this enum type. If Any one known about this kindly guide me.

    With reggards,
    Boopathiraja.N.

    Thanks in Advance for your guidance!.....

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How reset the Existing enum type values

    You cannot change the integral values of enum elements at runtime. You should make another enum if you need different values.

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

    Re: How reset the Existing enum type values

    If you want an enum with all the values equal to each other, then the enum is useless.

    Code:
    enum Shapes {
        Line = 0,
        Circle = 0
    }
    
    public void Method ()
    {
        Shapes shape = Shapes.Line;
        if (shape == Shapes.Circle)
           throw new WtfException ();
    }
    That code will throw a WtfException. Is this what you really want? If so, then you don't want an enum.
    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.

  4. #4
    Join Date
    Sep 2008
    Posts
    69

    Re: How reset the Existing enum type values

    Dear Mutant_Fruit & BigEd781,

    Thanks for ur guidance. This information proof for me. if i say in mine way to others they won't accept. that's why i asked guidance from your like senior.

    once again thansks for ur guidance.

    With Regards,
    Boopathiraja.N

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How reset the Existing enum type values

    Mutant, I can't give you rep, but +1 for making me laugh with the WtfException class. Hopefully the OP can convince their co-workers that they do not understand what an enum is for.

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