C
Cor Ligthert
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
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 ) said: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 said: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 ) said: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))
--
message 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 )" <news.microsoft.com> wrote in
message 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))
--
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... ;-).