枚举和随机数 [英] Enumerations And Random Numbers

查看:80
本文介绍了枚举和随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的问题,一直在唠叨我,但我从来没有抽出时间来讨论它。

如果我有一个这样的枚举


Fiend Enum TravelDirection







West < br $>
结束枚举





方向= TravelDirection

现在我要设置方向随机到一个TravelDirection枚举




如果我知道我的枚举在1到4之间我可以很容易地得到一个新的随机
可以做到,我有,但我正在寻找最简单的解决方案。

doesent似乎是枚举的Max属性。


如果这听起来很愚蠢,那么我就会道歉




-

OHM(Terry Burns)*使用以下内容给我发电子邮件*


Dim ch ()作为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) )

-

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))
--

推荐答案

嗨特里,

是否有理由认为你这样做对我来说很困难?我想我

错过了什么。


环境滴答计的最后位置+ 5除以5的两倍应该是我的b $ b意见诀窍。


Cor

单手男子(OHM - Terry Burns) < news.microsoft.com>
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 )" <news.microsoft.com>
我有一个基本的问题,一直在唠叨我,但我从来没有时间去看它。

如果我有一个这样的枚举

Fiend Enum TravelDirection
North
South

West
End Enum



方向= TravelDirection

现在我想将方向随机设置为其中一个TravelDirection
枚举值
<如果我知道我的枚举在1到4之间,我可以轻松获得一个新的随机数字并分配它,但是,正如我添加到枚举中,我不想担心编码所有的变化,所以我怎么能轻易做到这一点我知道
我能做到,我有,但我正在寻找最简单的解决方案。在那里
doesent似乎是枚举的Max属性。

如果这听起来很愚蠢,那么我就会道歉




> -
OHM(Terry Burns)*使用以下内容给我发电子邮件*

Dim ch()As Char =" ufssz / cvsotAhsfbuTpmvujpotXjui / OFU" .ToCharArray()
对于我因为Int32 = 0到ch.Length - 1
ch(i)= Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
下一步
Process.Start (" mailto:"& New String(ch))
-
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))
--



" One Handed Man( OHM - Terry Burns) < news.microsoft.com> schrieb:
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> schrieb:
如果我有一个这样的枚举

Fiend Enum TravelDirection
North
South

West 结束枚举



方向= TravelDirection

现在我想将方向随机设置为其中一个TravelDirection
枚举值

如果我知道我的枚举在1到4之间,我可以很容易地得到一个新的随机数字并分配它,但是,当我添加到枚举时,我不想要
担心编码所有的变化,所以我怎么能轻松地做到这一点我知道
我能做到,我有但我正在寻找最简单的解决方案。
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新随机

MsgBox(值(r.Next(0,Values.Length - 1))。ToString())

///


-

Herfried K. Wagner [MVP]

< ;网址:http://dotnet.mvps.org/>



\\\
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]
<URL:http://dotnet.mvps.org/>




" One Handed Man(OHM - 特里伯恩斯) < news.microsoft.com>写了

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote
我有一个基本的问题,一直在唠叨我,但我以前没有时间看过它。

如果我有这样的枚举

Fiend Enum TravelDirection


东西
结束枚举



方向= TravelDirection



应该是:


方向= TravelDirection.East


或其他一些特定值。你无法将

整个枚举分配给变量。

现在我想将方向随机设置为其中一个TravelDirection枚举
价值

如果我知道我的枚举在1到4之间,我可以轻松获得一个新的随机数字并分配它,但是,当我添加到枚举时,我不想<担心编码所有的变化,所以我怎么能轻松地做到这一点我知道我可以做到这一点,我有但我正在寻找最简单的解决方案。
doesent似乎是枚举的Max属性。


为什么不使用其中一个值?


West
MaxDirection = West End Enum
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



LFS


这篇关于枚举和随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆