c#循环列表随机数

时间:2016-12-01 14:44:25

标签: c#

我有随机数生成器

 Random random = new Random();
    int x = random.Next(25);

List<int> mylist = new List<int>() {1,2,3,4,5,6,7}

那么如何在列表中循环,如果列表中有随机数,则将该数字放入文本框或标签中?

1 个答案:

答案 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();
    }
}