Question: I have a string list and I am continuously adding elements to this list.
I do not want this list to grow beyond 6 elements(index 0 to 5). So once it reaches index[5], I do not want to grow the list, but instead add elements at the start of the list or do something similar to it. At any point, I would be printing the last 3 items added to this list ordered by item last added to this list. I have tried it below but i think it is crappy piece of code. After this piece of code, I would get the list count and print `UrlList[UrlList.Count - 1],UrlList[UrlList.Count - 2];,UrlList[UrlList.Count - 3]`
Pls help me with it

```
     if (UrlList.Count == 5)
    {
        var move = UrlList[5];
        UrlList.RemoveAt(5);
        UrlList.Insert(0, move);

         move = UrlList[4];
        UrlList.RemoveAt(4);
        UrlList.Insert(1, move);

         move = UrlList[3];
        UrlList.RemoveAt(3);
        UrlList.Insert(2, move);
         UrlList.Add(uri.ToString());
    }

    else
    {
        UrlList.Add(uri.ToString());
    }

```

Answer: 
If you want the *latest* items to be the *last* ones in the list, you can use this code:

```
const int Max_Capacity = 6;

if (UrlList.Count >= Max_Capacity) 
  UrlList.RemoveAt(0); // <- oldest (first) item should be removed

UrlList.Add(uri.ToString());

...

// Printing out the lastest 3 items:
int start = UrlList.Count <= 3 ? 0 : UrlList.Count - 3;

for (int i = start; i < UrlList.Count; ++i)
  Console.Out.WriteLine(UrlList[i]);

```
I think you better be using % Operator-.

In your case you can use:

```
UrlList.Insert((UrlList.count%6),move); 

```