[英]Append text list in VB.NET
What's wrong with this code and what should I do to make it work?这段代码有什么问题,我应该怎么做才能让它工作?
'Create an instance of the Random class
Dim rnd As New Random()
Dim randomNumberList As New List(Of Integer)
For x As Integer = 1 To 10
randomNumberList.Add(rnd.Next(0, 81))
If randomNumberList.Contains(strWords(StrwrVal.Text)) Then
Exit For
Else
TxtRnd1.AppendText(Environment.NewLine & randomNumberList)
End If
Next
How do I make it work properly?如何使其正常工作?
TxtRnd1.AppendText(Environment.NewLine & randomNumberList)
Try writing your code like this: I don't know why you included the If
block but I ommited it in this answer.尝试像这样编写代码:我不知道您为什么包含If
块,但我在此答案中省略了它。 You can add it back if you really need it.如果您真的需要它,您可以将其添加回来。
Dim rnd As New Random()
Dim randomNumberList As New List(Of Integer)
For x As Integer = 0 To 9
randomNumberList.Add(rnd.Next(0, 81))
TxtRnd1.AppendText(Environment.NewLine & CStr(randomNumberList(x)))
Next
Update更新
Fixed Bad If
Block修复了 Bad If
块
Dim rnd As New Random()
Dim randomNumberList As New List(Of Integer)
For x As Integer = 0 To 9
Integer tmp = rnd.Next(0, 81)
If (randomNumberList.Contains(tmp)) Then
Continue For
End If
randomNumberList.Add(tmp)
TxtRnd1.AppendText(Environment.NewLine & CStr(randomNumberList(x)))
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.