开发者

Index was outside the bounds of the array

开发者 https://www.devze.com 2023-01-06 06:58 出处:网络
I am getting \"Index was outside the bounds of the array.\" error when using this code: Dim RandomA As String = \"aAÀàÁâÄäÅåĀāĂ㥹ǞǟǺǻÃãÄ\"

I am getting "Index was outside the bounds of the array." error when using this code:

Dim RandomA As String = "aAÀàÁâÄäÅåĀāĂ㥹ǞǟǺǻÃãÄ"
Tex开发者_运维百科tBox1.Text = TextBox1.Text.Replace("a", RandomA((Int(Rnd() * RandomA.Count)) - 1))

I fail to see how the (random) index can be out of bounds?


Int(Rnd() * RandomA.Count) could return 0, and 0 - 1 is outside the bounds.


it is an edge condition for sure. the equation evaluates to -1 under certain random number conditions.

0

精彩评论

暂无评论...
验证码 换一张
取 消