我如何检查的时间我点击对列表大小的数量
本文关键字:列表 时间 何检查 检查 | 更新日期: 2023-09-27 18:12:25
int count = 0;
private void button1_Click(object sender, EventArgs e)
{
List<string> files = new DirectoryInfo(@"d:'")
.GetFiles("*.avi")
.Select(f => f.FullName + " " + FileSizeDisplay(f,70))//Select(f => Path.GetFileName(f.Name) + " " + FileSizeDisplay(f,70))
.ToList();
for (int i = files.Count -1; i >= 0; i--)
{
if (!files[i].EndsWith("MB") || files[i].EndsWith("0 MB"))
{
files.RemoveAt(i);
}
}
if (count < files.Count -1)
{
int index = files[count].IndexOf(" ");
filetoupload = files[count].Substring(0, index);
count += 1;
}
}
这一行:
if (count < files.Count -1)
例如,我在文件中有13个项目。Files是一个List<string>
。如果我只做If (count < files.Count)
,它会在到达13时抛出异常。
如果我在做if (count < files.Count -1)
,那么它会显示我点击/上传了12次/项。
当你这样做的时候:
files.RemoveAt(i);
您已经更改了数组中的项数。因此,下次当您尝试遍历该数组时,您应该期望它可能少于13项。