C# 如何将字符串添加到列表开头的列表中?
我有以下代码:C# 如何将字符串添加到列表开头的列表中?,c#,winforms,C#,Winforms,我有以下代码: 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, startI
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();
因此,imagesSatelliteUrls最终包含9个文件。
我想在imagesSatelliteUrls列表的开头添加另一个索引。
因此索引0将是一个字符串,例如:组1
然后剩下的9个索引将是文件
但是我如何只添加一次并在列表的开头添加字符串:group1?
因此,最终列表应该如下所示:
index[0] "Group 1"
index[1] file 1
index[2] file 2
.
.
.
.
index[9] file 9
所以我知道第一组是从1到9。在循环结束之后 编写此代码
imagesSatelliteUrls.Insert(0, "Group 1");
这将在第一个位置即索引0处插入组1。使用带有0索引的插入方法查找所需内容
imagesSatelliteUrls.Insert(0, "Group 1");