【发布时间】:2014-01-04 11:50:49
【问题描述】:
我有一个包含 f1、f2、f3、...、f6 等文件名的列表。我的
程序需要输出一个列表,文件名出现在
随机顺序如 f4,f1,f6,f2,f3,f5。 我想在列表中正确交换或移动字符串我有一个列表
名为 fileName 的大小 6 已经包含 6 个不同的文件名 I
我正在交换列表文件名中的文件名,如下所示和fil
也是一个用于记住当前字符串或文件名的字符串。
temp =-1;
foreach (Control control in tableLayoutPanel1.Controls) // run loop untill every control inside tablelayoutpanel1.Controls is check or read
{
Button btns = control as Button; // btn sotre the
current button in table.contr
if (btns != null) // check btn got a button from
the panel then
{
temp++;
int randomNumber = 0;
randomNumber = theArray[temp]; //this pic the random number from 0 index then 1 so on theArray already contains random number from 0 to 5 without any repitition and also tested
fil = fileName[randomNumber]; //fil for holding string
fileName[temp] = fileName[randomNumber]; // at filname[0]
swap or shift filename[randomNumber] random are between 0 to
5 and without repitition
fileName[randomNumber] = fil; // this line isnt even necessary
but to be safe i wrot
btns.BackgroundImage = images[randomNumber]; // change
btn image to current random image
copyImages.Add(images[randomNumber]);
btns.BackgroundImage = null; // i purposely doing this :)
}
使用该代码我可以交换字符串,但我不能交换它们
正确,因为它只运行了 6 次,所以它应该交换 6 个字符串
(每个都有不同的名字)在6个不同位置的列表中
在 fileName 列表中,但它没有发生一些字符串是
显示两三次,希望有人指出我是什么
做错了,没有索引超出范围或异常错误
我测试了一百次,请帮忙谢谢和任何想法
建议或一段代码会很有帮助,fil 只是将字符串存储在 fileName[temp] 的位置:) 和temp 只是在循环中从 0 变为 5
我不想打乱它们我只想根据给定的索引交换它们,我在我的代码中执行但不能正确地使用它theArray 已经包含 suffle 索引我只想将fileName[0] 索引分配给theArray[temp]如果你想看看,我可以把我的项目发给你,只要给我发个嗨到我的个人资料中显示的 id 就可以了
【问题讨论】: