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
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With