如何从列表中删除第一项并保持索引

Cal*_*vin 4 c#

我有一个列表,并希望删除第一个项目,同时保持下一个项目的索引相同.例如:

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

        return messageStatuses ;
    }
}
Run Code Online (Sandbox Code Playgroud)

结果返回

[0] -- apple
[1] -- grape
[2] -- orange
[3] -- peach
Run Code Online (Sandbox Code Playgroud)

删除第一项时,结果应为:

[1] -- grape
[2] -- orange
[3] -- peach
Run Code Online (Sandbox Code Playgroud)

Adi*_*dil 7

您可以使用字典

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);
Run Code Online (Sandbox Code Playgroud)

现在 dic[1]会给你苹果