test test - 3 years ago 194
C# Question

Array . How do you add text at Index in List or Array?

How do you add text at the end of all items in a List<> ?
Sorry If my question is confusing. I tried to edit it with desired output to make it clearer.

var hltv = new List<string>();
hltv.Add("How are you");
hltv.Add("What are you");
hltv.Add("Please stop");

foreach (var item in hltv)

I'm trying to add "doing" to the end of each item in hltv List.

So in the end I get the Output:

How are you doing

What are you doing

Please stop doing

Answer Source

One Line Solution-

hltv = hltv.Select(eachItem => string.Concat(eachItem, ' doing')).ToList();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download