I\'m trying to cycle through strings in a list with a foreach loop, but I don\'t know how to change the item that\'s being referenced - How can I change s
in the li
You can do this with Linq quite easily:
var newStringList = myStringList
.Select(s => s + "-")
.ToList();
If you really want to modify the existing list, you can use a classic for
loop, for example:
for (var i = 0; i < myStringList.Count; i++)
{
myStringList[i] = myStringList[i] + "-";
}
Try this
List<string> listString = new List<string>() { "1","2","3"};
listString=listString.Select(x => x + "-").ToList();