425,855 Members | 865 Online
Need help? Post your question and get tips & solutions from a community of 425,855 IT Pros & Developers. It's quick & easy.

# Enumerations And Random Numbers

 P: n/a I have a basic question thats been niggling me, but I never found time to look at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. There doesent seem to be a Max property for enumerations. If this sounds dumb, then I appologise -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- Nov 21 '05 #1
38 Replies

 P: n/a Hi Terry, Is there a reason that it seems that you do it for me difficult? I think I miss something. Two times the last position of environment tickcount + 5 divided by 5 should in my opinion do the trick. Cor "One Handed Man ( OHM - Terry Burns )" I have a basic question thats been niggling me, but I never found time tolook at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. There doesent seem to be a Max property for enumerations. If this sounds dumb, then I appologise -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- Nov 21 '05 #2

 P: n/a "One Handed Man ( OHM - Terry Burns )" schrieb: If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. \\\ Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) /// -- Herfried K. Wagner [MVP] Nov 21 '05 #3

 P: n/a "One Handed Man ( OHM - Terry Burns )" wrote I have a basic question thats been niggling me, but I never found time to look at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection That should be: Direction = TravelDirection.East Or some other specific value. You wouldn't be able to assign the entire enum to a variable. Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. There doesent seem to be a Max property for enumerations. Why not use one of the values? East West MaxDirection = West End Enum LFS Nov 21 '05 #4

 P: n/a Sorry, I think I F*c(ed up here. What I meant was how to set the variable to a Random number somwhere in the range of the enumeration. So Direction = ( Some Random Number In the Range ) I dont want to explicitly set it like this Direction = RandomNumber( 0, 10) I was looking for something more like Direction = RandomNumber.next( 0, MyEnumeration.Max ) See what I mean, I mat have missed something here -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Larry Serflaten" wrote in message news:eb**************@TK2MSFTNGP10.phx.gbl... "One Handed Man ( OHM - Terry Burns )" wrote I have a basic question thats been niggling me, but I never found time to look at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection That should be: Direction = TravelDirection.East Or some other specific value. You wouldn't be able to assign the entire enum to a variable. Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. There doesent seem to be a Max property for enumerations. Why not use one of the values? East West MaxDirection = West End Enum LFS Nov 21 '05 #5

 P: n/a "Herfried K. Wagner [MVP]" wrote Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) The maxValue of Next needs to be one greater than the last value desired: Dim Values() As AnchorStyles = CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length)).ToString()) LFS Nov 21 '05 #6

 P: n/a "Larry Serflaten" schrieb: Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) The maxValue of Next needs to be one greater than the last value desired: Dim Values() As AnchorStyles = CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #7

 P: n/a "Mr Newbie" wrote What I meant was how to set the variable to a Random number somwhere in the range of the enumeration. So Direction = ( Some Random Number In the Range ) As Herfried shows, the best solution is to add the members to an array, and pick some random value out of the array. It may be that the values in the Enum are NOT sequential, so that you can't just pick some number from 0 to some max value. With the actual Enum values in an array, you can be sure picking one element of the array will give you some value that is actually in the Enum. Make sense? BTW, another route would be something like this: Dim pick As Integer() = New Integer() {TravelDirection.North, TravelDirection.South, _ TravelDirection.East, TravelDirection.West} test = pick(Rnd.Next(0, 4)) ;-) LFS Nov 21 '05 #8

 P: n/a Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl... "Larry Serflaten" schrieb: Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) The maxValue of Next needs to be one greater than the last value desired: Dim Values() As AnchorStyles = CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #9

 P: n/a Cheers Cor -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Cor Ligthert" wrote in message news:%2******************@TK2MSFTNGP09.phx.gbl... Hi Terry, Is there a reason that it seems that you do it for me difficult? I think I miss something. Two times the last position of environment tickcount + 5 divided by 5 should in my opinion do the trick. Cor "One Handed Man ( OHM - Terry Burns )" I have a basic question thats been niggling me, but I never found time tolook at it before. If I have an enumeration such as this Fiend Enum TravelDirection North South East West End Enum and Direction = TravelDirection Now I want to set the Direction Randomly to one of the TravelDirection enum values If I know that my enum is between 1 and 4 I can easily get a new random number and assign it, however, As I add to the enumeration, I wont want to worry about coding all the changes, so how could I easily do this I know I can do it, and I have but Im looking for the most simple solution. There doesent seem to be a Max property for enumerations. If this sounds dumb, then I appologise -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- Nov 21 '05 #10

 P: n/a Very true, I didnt think of that, yes they may not be sequentional good point. However, it would however, be nice if this was built into the enum class. -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Larry Serflaten" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... "Mr Newbie" wrote What I meant was how to set the variable to a Random number somwhere in the range of the enumeration. So Direction = ( Some Random Number In the Range ) As Herfried shows, the best solution is to add the members to an array, and pick some random value out of the array. It may be that the values in the Enum are NOT sequential, so that you can't just pick some number from 0 to some max value. With the actual Enum values in an array, you can be sure picking one element of the array will give you some value that is actually in the Enum. Make sense? BTW, another route would be something like this: Dim pick As Integer() = New Integer() {TravelDirection.North, TravelDirection.South, _ TravelDirection.East, TravelDirection.West} test = pick(Rnd.Next(0, 4)) ;-) LFS Nov 21 '05 #11

 P: n/a OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl... Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl... "Larry Serflaten" schrieb: Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) The maxValue of Next needs to be one greater than the last value desired: Dim Values() As AnchorStyles = CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #12

 P: n/a OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl... Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl... "Larry Serflaten" schrieb:> Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles))> Dim r As New Random> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) The maxValue of Next needs to be one greater than the last value desired: Dim Values() As AnchorStyles = CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) Dim r As New Random MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #13

 P: n/a Terry, I hope you do not mind that I answer, In my opinion is an Enum the best used when it has the values 1 2 4 8 Than you can do an OR or whatever with it, and has it no sence to know the max value (in this case 15) or F However just my opinion. Cor "One Handed Man ( OHM - Terry Burns )" OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl... Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl... "Larry Serflaten" schrieb:>> Dim Values() As AnchorStyles =>> [Enum].GetValues(GetType(AnchorStyles))>> Dim r As New Random>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())>> The maxValue of Next needs to be one greater than the last value> desired:>> Dim Values() As AnchorStyles => CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles())> Dim r As New Random> MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #14

 P: n/a Hi Cor, Im not sure if you understood my origional post. What I wanted was to be able to choose randomly any element from the Enum members, in order to do this you need to know the number of elements. Herfried's code will do this quite well. I went on to say that It would be nice if the Enum class would be able to choose one element at Random and Jay said he thought this was to much and it probably is, however, it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. Unfortunately you dont seem to be able to inherit an Enum or I would have wrapped it myself. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Cor Ligthert" wrote in message news:OB**************@TK2MSFTNGP12.phx.gbl... Terry, I hope you do not mind that I answer, In my opinion is an Enum the best used when it has the values 1 2 4 8 Than you can do an OR or whatever with it, and has it no sence to know the max value (in this case 15) or F However just my opinion. Cor "One Handed Man ( OHM - Terry Burns )" OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl... Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl...> "Larry Serflaten" schrieb:>>> Dim Values() As AnchorStyles =>>> [Enum].GetValues(GetType(AnchorStyles))>>> Dim r As New Random>>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())>>>> The maxValue of Next needs to be one greater than the last value>> desired:>>>> Dim Values() As AnchorStyles =>> CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles())>> Dim r As New Random>> MsgBox(Values(r.Next(0, Values.Length)).ToString())>> ACK, I should have read the documentation... ;-).>> --> Herfried K. Wagner [MVP]> Nov 21 '05 #15

 P: n/a Terry, "One Handed Man ( OHM - Terry Burns )" schrieb: I went on to say that It would be nice if the Enum class would be able to choose one element at Random and Jay said he thought this was to much and it probably is In this particular case, I agree with Jay. Picking a random enumeration constant doesn't have anything to do with enums and thus should not be added. however, it would be nice if the Enum could report the number of elements it has I agree up to this point that this would be a nice addition to enumerations. -- Herfried K. Wagner [MVP] Nov 21 '05 #16

 P: n/a "One Handed Man ( OHM - Terry Burns )" wrote it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. But Herfried has already shown how to do that. When you put the elements in an array, the array itself will tell you how many there are. Or, you can get the value from the Enum class: Dim cnt As Integer = [Enum].GetValues(GetType(MyEnum)).Length Debug.WriteLine(cnt) I don't see how they could add anything else. What if you wanted to have a member called Length? If it was used as a shared member of your enum, you couldn't use it: cnt = MyEnum.Length ' ??? Do you see how they really shouldn't add anything to your enum except what you list as members of the enum? LFS Nov 21 '05 #17

 P: n/a OHM, OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? That's not what I stated! :-| I think having the Enum Class report the number of elements an enum contains might be a good thing. Although you can easily get the number from Enum.GetNames or Enum.GetValues. I say "might be a good thing", as it could be too easy to introduce problems as Enum values are not required to be contiguous, nor start with zero. What I said would be a bad thing, and I attempted to be very specific, is for System.Enum to have a function that would return a random value (ala Herfried's code). Yes, your code needs it, however is Returning a random value really a realistic behavior that all Enums should behave? I don't see that it is, hence I don't think Enum should possess that ability. Now I do agree it would be nice to add our own functions to specific enums, such as your TravelDirection enum might have the ability to return a random value. Unfortunately the designers at MS decided not to allow that. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:O8**************@TK2MSFTNGP11.phx.gbl... OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay <> Nov 21 '05 #18

 P: n/a Larry, I could see a Enum.GetLength function: Dim cnt As Integer = [Enum].GetLength(GetType(MyEnum)) That would not need to actually create & return the array of values. However!!! This could cause problems, as Enums are not required to start with zero nor are they required to be contiguous. In other words, code such as: Public Enum MyEnum None = 0 Value1 = 55 Value2 = 65 Value3 = 75 End Enum 'For value As MyEnum = 0 to [Enum].GetLength(GetType(MyEnum)) For value As MyEnum = 0 to [Enum].GetValues(GetType(MyEnum)).Length Debug.WriteLine(value, value.ToString()) Next Would cause all sorts of mischief. Where as this one does not: For Each value As MyEnum In [Enum].GetValues(GetType(MyEnum)) Debug.WriteLine(value, value.ToString()) Next Hope this helps Jay "Larry Serflaten" wrote in message news:uc**************@TK2MSFTNGP11.phx.gbl... "One Handed Man ( OHM - Terry Burns )" wrote it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. But Herfried has already shown how to do that. When you put the elements in an array, the array itself will tell you how many there are. Or, you can get the value from the Enum class: Dim cnt As Integer = [Enum].GetValues(GetType(MyEnum)).Length Debug.WriteLine(cnt) I don't see how they could add anything else. What if you wanted to have a member called Length? If it was used as a shared member of your enum, you couldn't use it: cnt = MyEnum.Length ' ??? Do you see how they really shouldn't add anything to your enum except what you list as members of the enum? LFS Nov 21 '05 #19

 P: n/a For one, enum per CLI specification cannot have any methods\properties\events of its own. It can't even have any instance fields except one, and thats used for defining the underlying type of the enum. So forget about extending it. Could it add a shared method Count that excepts an enum type and returns the number of fields? Maybe, but I'm not sure it would be a good design decision. Lets say it has the shared Count\Length method, Count\Length denotes arrays\collections\containers, and enum is not any of these. Matter of fact an enum does not contain anything except the one instance variable as perviously mentioned. Could it represent the size of the enum? No because an enum defines named literals and thats it. Could it represent the number of valid values of the enum? Not really because I can assign any value to an enum field whether its defined by the enum type or not. Ex. Public Enum Fruit Apple Orange End Enum Dim F As Fruit F = Ctype(10,Fruit) What it actually represents is the number of named literals defined by the enum type. If this is true then what good is this value when used against the enum itself? What does it tell you about the enum and how is it useful? I can't really think of anything useful off the top of my head. Where it does become useful is when you ask for the name or value arrays, and arrays already of the property length, and it properly describes the array not the enum Anyways thinking out loud and just my two cents JD "One Handed Man ( OHM - Terry Burns )" wrote in message news:O8**************@TK2MSFTNGP11.phx.gbl... OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl... Thanks 2 both, i've used something similar in the past but its just a shame this was not built in to an enum class. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:uT*************@TK2MSFTNGP11.phx.gbl... "Larry Serflaten" schrieb:>> Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles))>> Dim r As New Random>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())>> The maxValue of Next needs to be one greater than the last value> desired:>> Dim Values() As AnchorStyles => CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles())> Dim r As New Random> MsgBox(Values(r.Next(0, Values.Length)).ToString()) ACK, I should have read the documentation... ;-). -- Herfried K. Wagner [MVP] Nov 21 '05 #20

 P: n/a Hi Terry, As I said in my first post I do not know what you want to do, an Enum is in my opinion to get a value using a keyword in a program. Something as Direction = TravelDirection.North OR TravelDirection.West (What would give as the Enum values where 1 2 4 8 using the normal situation give 3 and than I could use that to go NorthWest in my screen) However when I want to know what my randomnumber 4 would be I would just use a hashtable, where it would give a value "East" (accoording to your table). So I am curious in what situation you want to use this. Cor When I would get a value "One Handed Man ( OHM - Terry Burns )" schreef in bericht news:%2****************@TK2MSFTNGP12.phx.gbl... Hi Cor, Im not sure if you understood my origional post. What I wanted was to be able to choose randomly any element from the Enum members, in order to do this you need to know the number of elements. Herfried's code will do this quite well. I went on to say that It would be nice if the Enum class would be able to choose one element at Random and Jay said he thought this was to much and it probably is, however, it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. Unfortunately you dont seem to be able to inherit an Enum or I would have wrapped it myself. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Cor Ligthert" wrote in message news:OB**************@TK2MSFTNGP12.phx.gbl... Terry, I hope you do not mind that I answer, In my opinion is an Enum the best used when it has the values 1 2 4 8 Than you can do an OR or whatever with it, and has it no sence to know the max value (in this case 15) or F However just my opinion. Cor "One Handed Man ( OHM - Terry Burns )" OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:uM**************@TK2MSFTNGP15.phx.gbl...> Thanks 2 both, i've used something similar in the past but its just a> shame this was not built in to an enum class.>> Cheers>> --> OHM ( Terry Burns ) * Use the following to email me *>> Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()> For i As Int32 = 0 To ch.Length - 1> ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)> Next> Process.Start("mailto:" & New String(ch))> -->>> "Herfried K. Wagner [MVP]" wrote in message> news:uT*************@TK2MSFTNGP11.phx.gbl...>> "Larry Serflaten" schrieb:>>>> Dim Values() As AnchorStyles =>>>> [Enum].GetValues(GetType(AnchorStyles))>>>> Dim r As New Random>>>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())>>>>>> The maxValue of Next needs to be one greater than the last value>>> desired:>>>>>> Dim Values() As AnchorStyles =>>> CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles())>>> Dim r As New Random>>> MsgBox(Values(r.Next(0, Values.Length)).ToString())>>>> ACK, I should have read the documentation... ;-).>>>> -->> Herfried K. Wagner [MVP]>> >> Nov 21 '05 #21

 P: n/a Yes I understand that. However, it would be an easy thing to have incorporated into the Class and would have made coding just slightly simpler. However, this is fairly academic I know. Regards -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Larry Serflaten" wrote in message news:uc**************@TK2MSFTNGP11.phx.gbl... "One Handed Man ( OHM - Terry Burns )" wrote it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. But Herfried has already shown how to do that. When you put the elements in an array, the array itself will tell you how many there are. Or, you can get the value from the Enum class: Dim cnt As Integer = [Enum].GetValues(GetType(MyEnum)).Length Debug.WriteLine(cnt) I don't see how they could add anything else. What if you wanted to have a member called Length? If it was used as a shared member of your enum, you couldn't use it: cnt = MyEnum.Length ' ??? Do you see how they really shouldn't add anything to your enum except what you list as members of the enum? LFS Nov 21 '05 #22

 P: n/a OOPS, Ive upset Jay Sorry -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:uz**************@TK2MSFTNGP14.phx.gbl... OHM, OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? That's not what I stated! :-| I think having the Enum Class report the number of elements an enum contains might be a good thing. Although you can easily get the number from Enum.GetNames or Enum.GetValues. I say "might be a good thing", as it could be too easy to introduce problems as Enum values are not required to be contiguous, nor start with zero. What I said would be a bad thing, and I attempted to be very specific, is for System.Enum to have a function that would return a random value (ala Herfried's code). Yes, your code needs it, however is Returning a random value really a realistic behavior that all Enums should behave? I don't see that it is, hence I don't think Enum should possess that ability. Now I do agree it would be nice to add our own functions to specific enums, such as your TravelDirection enum might have the ability to return a random value. Unfortunately the designers at MS decided not to allow that. Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:O8**************@TK2MSFTNGP11.phx.gbl... OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... OHM, ?? You want a method on the Enum class that randomly returns one of the Enum's values? IMHO Such a function would suggest that the Enum class is trying to do too much! I would use code similar to Herfried's in a context appropriate class, probably the class that was consuming the random enum value. Hope this helps Jay <> Nov 21 '05 #23

 P: n/a This is more of an academic point really. As H has shows this is already possible with a few lines of code, but I was hoping to have done this with one simple single line of code. -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Cor Ligthert" wrote in message news:u1**************@TK2MSFTNGP12.phx.gbl... Hi Terry, As I said in my first post I do not know what you want to do, an Enum is in my opinion to get a value using a keyword in a program. Something as Direction = TravelDirection.North OR TravelDirection.West (What would give as the Enum values where 1 2 4 8 using the normal situation give 3 and than I could use that to go NorthWest in my screen) However when I want to know what my randomnumber 4 would be I would just use a hashtable, where it would give a value "East" (accoording to your table). So I am curious in what situation you want to use this. Cor When I would get a value "One Handed Man ( OHM - Terry Burns )" schreef in bericht news:%2****************@TK2MSFTNGP12.phx.gbl... Hi Cor, Im not sure if you understood my origional post. What I wanted was to be able to choose randomly any element from the Enum members, in order to do this you need to know the number of elements. Herfried's code will do this quite well. I went on to say that It would be nice if the Enum class would be able to choose one element at Random and Jay said he thought this was to much and it probably is, however, it would be nice if the Enum could report the number of elements it has to simplify choosing one from its return element values array. Unfortunately you dont seem to be able to inherit an Enum or I would have wrapped it myself. Cheers -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Cor Ligthert" wrote in message news:OB**************@TK2MSFTNGP12.phx.gbl... Terry, I hope you do not mind that I answer, In my opinion is an Enum the best used when it has the values 1 2 4 8 Than you can do an OR or whatever with it, and has it no sence to know the max value (in this case 15) or F However just my opinion. Cor "One Handed Man ( OHM - Terry Burns )" OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...> OHM,> ??>> You want a method on the Enum class that randomly returns one of the> Enum's values?>> IMHO Such a function would suggest that the Enum class is trying to do> too much!>> I would use code similar to Herfried's in a context appropriate class,> probably the class that was consuming the random enum value.>> Hope this helps> Jay>> "One Handed Man ( OHM - Terry Burns )" wrote in> message news:uM**************@TK2MSFTNGP15.phx.gbl...>> Thanks 2 both, i've used something similar in the past but its just a>> shame this was not built in to an enum class.>>>> Cheers>>>> -->> OHM ( Terry Burns ) * Use the following to email me *>>>> Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()>> For i As Int32 = 0 To ch.Length - 1>> ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)>> Next>> Process.Start("mailto:" & New String(ch))>> -->>>>>> "Herfried K. Wagner [MVP]" wrote in>> message news:uT*************@TK2MSFTNGP11.phx.gbl...>>> "Larry Serflaten" schrieb:>>>>> Dim Values() As AnchorStyles =>>>>> [Enum].GetValues(GetType(AnchorStyles))>>>>> Dim r As New Random>>>>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString())>>>>>>>> The maxValue of Next needs to be one greater than the last value>>>> desired:>>>>>>>> Dim Values() As AnchorStyles =>>>> CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles())>>>> Dim r As New Random>>>> MsgBox(Values(r.Next(0, Values.Length)).ToString())>>>>>> ACK, I should have read the documentation... ;-).>>>>>> -->>> Herfried K. Wagner [MVP]>>> >>>>>> Nov 21 '05 #24

 P: n/a Yes your last point is the one I am making -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "JD" wrote in message news:SXUgd.26314\$HA.22935@attbi_s01... For one, enum per CLI specification cannot have any methods\properties\events of its own. It can't even have any instance fields except one, and thats used for defining the underlying type of the enum. So forget about extending it. Could it add a shared method Count that excepts an enum type and returns the number of fields? Maybe, but I'm not sure it would be a good design decision. Lets say it has the shared Count\Length method, Count\Length denotes arrays\collections\containers, and enum is not any of these. Matter of fact an enum does not contain anything except the one instance variable as perviously mentioned. Could it represent the size of the enum? No because an enum defines named literals and thats it. Could it represent the number of valid values of the enum? Not really because I can assign any value to an enum field whether its defined by the enum type or not. Ex. Public Enum Fruit Apple Orange End Enum Dim F As Fruit F = Ctype(10,Fruit) What it actually represents is the number of named literals defined by the enum type. If this is true then what good is this value when used against the enum itself? What does it tell you about the enum and how is it useful? I can't really think of anything useful off the top of my head. Where it does become useful is when you ask for the name or value arrays, and arrays already of the property length, and it properly describes the array not the enum Anyways thinking out loud and just my two cents JD "One Handed Man ( OHM - Terry Burns )" wrote in message news:O8**************@TK2MSFTNGP11.phx.gbl... OK, why do you think its too much to ask of an Enum Class to be able to report the number of elements it contains ? -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Jay B. Harlow [MVP - Outlook]" wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl... > OHM, > ?? > > You want a method on the Enum class that randomly returns one of the > Enum's values? > > IMHO Such a function would suggest that the Enum class is trying to do too > much! > > I would use code similar to Herfried's in a context appropriate class, > probably the class that was consuming the random enum value. > > Hope this helps > Jay > > "One Handed Man ( OHM - Terry Burns )" wrote in > message news:uM**************@TK2MSFTNGP15.phx.gbl... >> Thanks 2 both, i've used something similar in the past but its just a >> shame this was not built in to an enum class. >> >> Cheers >> >> -- >> OHM ( Terry Burns ) * Use the following to email me * >> >> Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() >> For i As Int32 = 0 To ch.Length - 1 >> ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) >> Next >> Process.Start("mailto:" & New String(ch)) >> -- >> >> >> "Herfried K. Wagner [MVP]" wrote in message >> news:uT*************@TK2MSFTNGP11.phx.gbl... >>> "Larry Serflaten" schrieb: >>>>> Dim Values() As AnchorStyles = [Enum].GetValues(GetType(AnchorStyles)) >>>>> Dim r As New Random >>>>> MsgBox(Values(r.Next(0, Values.Length - 1)).ToString()) >>>> >>>> The maxValue of Next needs to be one greater than the last value >>>> desired: >>>> >>>> Dim Values() As AnchorStyles = >>>> CType([Enum].GetValues(GetType(AnchorStyles)), AnchorStyles()) >>>> Dim r As New Random >>>> MsgBox(Values(r.Next(0, Values.Length)).ToString()) >>> >>> ACK, I should have read the documentation... ;-). >>> >>> -- >>> Herfried K. Wagner [MVP] >>> >> >> > > Nov 21 '05 #25

 P: n/a Terry, (you didn't upset me per se). I agree the Framework designers and/or the language designers could have included the feature, however should they have? As JD has explained they did not. Should it be a property of a specific Enum Fiend Enum TravelDirection North South East West End Enum Dim count As Integer = TravelDirection.Length Or a shared function of all Enums? Dim count As Integer = [Enum].GetLength(GetType(TravelDirection)) Or maybe even just a VB.NET specific keyword? Dim count As Integer = Len(TravelDirection) The benefit of the specific property is it is coupled to a specific Enum, although it may hide a value of the Enum... Of course you can approximate this with adding another value to the Enum: Fiend Enum TravelDirection North South East West Length ' represents the 4 "real" elements in this Enum End Enum The danger of TravelDirection.Length is it will show up on Enum.GetNames & Enum.GetValues, Enum.Parse, and Enum.IsDefined! The benefit of the Shared Function is it is consistent with Enum.GetNames & Enum.GetValues. The benefit of the keyword is that there would be no changes to the Framework itself. Of course you can approximate the keyword with Herfried's function. Public Function Len(ByVal enumType As Type) As Integer Return [Enum].GetValues(enumType).Length End Function Dim count As Integer = Len(GetType(TravelDirection)) However!!! My concerns of such a member could cause problems still stands, as Enums are not required to start with zero nor are they required to be contiguous. In other words if I have a Flags enum, what does Enum.Length really represent? _ Friend Enum TravelDirection None = 0 North = 1 South = 2 East = 4 West = 8 NorthWest = North Or West ... All = North Or South Or East Or West End Enum Should All or NorthWest be included in the Length or not? I hope you realize I am not disagreeing as much as I am being overly cautious of such a member. I'm not sure if the designers had these same feelings when they left the member out of Enum or not... Hope this helps Jay "One Handed Man ( OHM - Terry Burns )" wrote in message news:eu**************@TK2MSFTNGP12.phx.gbl... Despite your explaination, I dont think it would be that difficult or wrong to have provided a property to return the number of elements, but that's my opinion. I for one would have welcomed that. Thanks for your views anyway. Regards - OHM -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- Nov 21 '05 #28

 P: n/a "JD" schrieb: Asking a type to return the number of fields it contains, so you can treat the type's fields like an array, when the type is not an array, would cause confusion. The Enum type is not an array of values, its a type with fields that have literal values. There is a difference. If you want to reflect over the type to get the fields array, and iterate over that, thats more expressive and clear. Or in the Enum's case you can get the values and names and iterate over them. Mhm... With a similar argument it would be possible to say that getting the enum's possible values is "bad design" because an enum can take combinations of the values too, and the method may thus be misleading. To make a conclusion: I agree that there is no need to add this property. There was a need to add methods for getting the names of an enumeration's constants, and their values, respectively. By providing these two ways to get information about the enum, it's not directly required to add a property that will return the number of constants defined in the enum, because this would be simple "wrapper" code, as posted in previous messages in this thread. -- Herfried K. Wagner [MVP] Nov 21 '05 #32

 P: n/a "Jay B. Harlow [MVP - Outlook]" wrote What should have been considered, is some means to provide static linking instead of assuming 'dynamic linking' is right for all cases. Have you looked at .NET Modules (a .netmodule file) (not to be confused with VB.NET's Module keyword). No, I hadn't (I'm not too keen on compiling from the command line ;-) That does not seem to be picking and choosing only the used functions out of the modules. It apparently requires that the entire module be present at runtime, which defeats the purpose.... Imagine, for example, I create my own Math class, and in one project I only use ABS, SIN and COS. Those are the only functions I want included in the EXE because there may be a hundred or more functions in that class that I am not using. I might have my own Math class, File access module, Dialog module and a number of others all neatly organized into namespaces and classes, that I want to use part of, but I don't want to ship all of them in their entirety when I am only using a handful of methods from each of them. http://msdn.microsoft.com/library/de...fAddmodule.asp From that page: -------- All modules added with /addmodule must be in the same directory as the output file at run time. That is, you can specify a module in any directory at compile time, but the module must be in the application directory at run time. If it is not, you get a System.TypeLoadException error. --------- So that seems to be saying the entire module must be shipped with the assembly.... LFS Nov 21 '05 #33

 P: n/a OK, I'm convinced, after listening to all viewpoints on this, I think I finally agree that the Enum class is positioned about where it should be. Thanks to all for an interesting discussion. -- OHM ( Terry Burns ) * Use the following to email me * Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray() For i As Int32 = 0 To ch.Length - 1 ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1) Next Process.Start("mailto:" & New String(ch)) -- "Herfried K. Wagner [MVP]" wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl... "JD" schrieb: Asking a type to return the number of fields it contains, so you can treat the type's fields like an array, when the type is not an array, would cause confusion. The Enum type is not an array of values, its a type with fields that have literal values. There is a difference. If you want to reflect over the type to get the fields array, and iterate over that, thats more expressive and clear. Or in the Enum's case you can get the values and names and iterate over them. Mhm... With a similar argument it would be possible to say that getting the enum's possible values is "bad design" because an enum can take combinations of the values too, and the method may thus be misleading. To make a conclusion: I agree that there is no need to add this property. There was a need to add methods for getting the names of an enumeration's constants, and their values, respectively. By providing these two ways to get information about the enum, it's not directly required to add a property that will return the number of constants defined in the enum, because this would be simple "wrapper" code, as posted in previous messages in this thread. -- Herfried K. Wagner [MVP] Nov 21 '05 #34