我創建了一個for循環,並且我希望每次循環運行時都將隨機文本從數組中加載到不同的標籤中。我所有的標籤添加到我的形式,稱爲LBL1,LBL2,LBL3等在循環C中更改標籤#
Random r = new Random();
for (int i = 1; i <= 4; i++)
{
int randomtext = r.Next(0, mytext.GetLength(0)); //choosing random element of array to be added to label
//this is where I want to add the text to a random label
}
我怎樣才能文本每次添加一個隨機的標籤嗎?我需要創建一個數組還是某種列表?我希望每次只需添加i作爲變量名稱的後綴。很抱歉,如果這很明顯,我是C#的新手。
謝謝!
這是Windows窗體(桌面應用程序), WPF,MVC或Web窗體? –
我假設他在桌面上。那麼可能是WinForms或WPF? –