我有这个代码:
for (int i = 0; i < Maps.Count; i++)
{
string startTag = FirstTags[i];
string endTag = LastTags[i];
startIndex = Maps[i].IndexOf(startTag);
while (startIndex > 0)
{
endIndex = Maps[i].IndexOf(endTag, startIndex);
if (endIndex == -1)
{
break;
}
string t = Maps[i].Substring(startIndex, endIndex - startIndex + endTag.Length);
if (i == 0)
{
imagesSatelliteUrls.Add(t);
}
position = endIndex + endTag.Length;
startIndex = Maps[i].IndexOf(startTag, position);
}
imagesSatelliteUrls = imagesSatelliteUrls.OrderBy(q => q).ToList();
所以第一个迭代/循环 i = 0 然后它进入一个 while 循环。然后我做了:
if (i == 0)
{
imagesSatelliteUrls.Add(t);
}
所以最后 imagesSatelliteUrls 包含 9 个文件。我想在 imagesSatelliteUrls 列表的开头添加另一个索引。例如,索引 0 的字符串将是:“Group 1”,然后其余 9 索引将是文件。
但是我如何只添加一次并在列表的开头添加字符串:“Group 1”?所以最后列表应该是这样的:
index[0] "Group 1"
index[1] file 1
index[2] file 2
.
.
.
.
index[9] file 9
所以我知道“第 1 组”是从 1 到 9。