如何在同一收集地点replace列表中的值

如何replace同一位置的collections列表中的值?

0 = cat 1 = dog 2 = bird 

snailreplace2

你的意思是:

 yourCollection[2] = "Snail"; 

在一个更大的List<T>集合中,你想find索引来replace…:

  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.RemoveAt(2); animals.Insert(2, "snail");