我有随机数生成器
Random random = new Random();
int x = random.Next(25);
和
List<int> mylist = new List<int>() {1,2,3,4,5,6,7}
那么如何在列表中循环,如果列表中有随机数,则将该数字放入文本框或标签中?
答案 0 :(得分:0)
//Loop through each int in the list
foreach (int i in myList)
{
//If the current int (i) equals the random (x)...
if (i == x)
{
//Set it as the TextBox text (substitute out "someTextBox" for your TextBox or Label
someTextBox.Text = i.ToString();
}
}