-1

I have this code:

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();

So the first itertion/loop i = 0 Then its getting into a while loop. Then i did:

if (i == 0)
{
    imagesSatelliteUrls.Add(t);
}

So in the end imagesSatelliteUrls contain 9 files. I want to add another index to the beginning of the imagesSatelliteUrls List. A string so index 0 will be for example: "Group 1" And then the rest 9 index will be the files.

But how do i add only once and to the beginning of the List the string: "Group 1" ? So in the end the List should look like:

index[0] "Group 1"
index[1] file 1
index[2] file 2
.
.
.
.
index[9] file 9

So i know that "Group 1" is from 1 to 9.

David Arno
  • 42,717
  • 16
  • 86
  • 131
Doron Muzar
  • 443
  • 1
  • 10
  • 26

1 Answers1

6

After your loop ends then

write this code

imagesSatelliteUrls.Insert(0, "Group 1");

This will insert "Group 1" at the First location i.e index zero.

tariq
  • 2,193
  • 15
  • 26