How to replace value in list at same collection location [duplicate]
How do I replace a value in a collection list at the same location?
0 = cat
1 = dog
2 = bird
replace 2
with snail
?
Do you mean:
yourCollection[2] = "Snail";
In a bigger List<T>
collection, you would like to find index to replace...with:
var i = animals.FindIndex(x => x == "Dog");
animals[i] = "Snail";
List<string> animals = new List<string>();
animals.Add("cat");
animals.Add("dog");
animals.Add("bird");
animals.Add("fish");
animals.RemoveAt(2);
animals.Insert(2, "snail");
精彩评论