Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove first item from list and keep index

Tags:

c#

I have a list and want to remove the first item while keeping the index of the next the same. For example:

public List<string> Fruit
{
    get
    {
        List<string> fruits = dataSource.GetFruits();

        return messageStatuses ;
    }
}

result returned

[0] -- apple
[1] -- grape
[2] -- orange
[3] -- peach

when the first item is remove the result should be:

[1] -- grape
[2] -- orange
[3] -- peach
like image 743
Calvin Avatar asked Dec 27 '22 19:12

Calvin


1 Answers

You can use dictionary for this

Dictionary<int,string> dic = new Dictionary<int,string>();

dic.Add(0,"Apple");
dic.Add(1,"Grape");
dic.Add(2,"Orange");
dic.Add(3,"Peach");

dic.Remove(0);

Now dic[1] will give you "Grape"

like image 163
Adil Avatar answered Jan 12 '23 01:01

Adil