Results 1 to 6 of 6

Thread: Can you For Each an Enumerator?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188

    Can you For Each an Enumerator?

    I'm not sure if this is possible or not thats why I am asking my enumerator

    Code:
    enum times
    {
      time_1
      time_2
      time_3
      time_4
      time_5
      time_6
      time_7
      time_8
      time_9
    }
    Is there some way I could enumerate through each value of the enumerator :S if that makes any since at all.

    eg.

    Code:
    foreach evalue in times
    {
      if (evalue == time_6) dosomething();
    }

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    like this maybe
    VB Code:
    1. [color=blue]enum[/color] times
    2.         {
    3.             time_1,
    4.             time_2,
    5.             time_3,
    6.             time_4,
    7.             time_5,
    8.             time_6,
    9.             time_7,
    10.             time_8,
    11.             time_9,
    12.         }
    13.  
    14.     [color=green]// to implement in a void or something ...[/color]
    15.         times tm = new times();
    16.  
    17.         [color=blue]foreach[/color](System.Reflection.FieldInfo f [color=blue]in[/color] tm.GetType().GetFields())
    18.             {
    19.                 [color=blue]if[/color](f.Name != "time_6")
    20.                 {
    21.                     [color=green]// do something. [/color]
    22.                 }
    23.             }
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    good but I really need to return the values not the names

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    for the values m8 you do this ...
    VB Code:
    1. [color=blue]private void[/color] button1_Click([color=blue]object[/color] sender, System.EventArgs e)
    2.         {
    3.          
    4.         times tm = new times();
    5.  
    6.         [color=blue]foreach[/color](System.Reflection.FieldInfo f [color=blue]in[/color] tm.GetType().GetFields())
    7.             {
    8.                 [color=blue]if[/color](Convert.ToInt32(f.GetValue(tm)) == 6)
    9.                     {
    10.                         MessageBox.Show("item value 6 found");
    11.                     }
    12.             }
    13.         }
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    o tanx, I ended up not using but it's nice ot know ;p

  6. #6
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Can you For Each an Enumerator?

    Originally posted by Tewl
    Is there some way I could enumerate through each value of the enumerator :S if that makes any since at all.
    That's what arrays are for
    I don't live here any more.

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