I have a List names = new List {“aa”, “bb”, “cc”}. I want to use the LINQ way and appennd a string to each one of them (instead of String builder and a foreach loop specifically). So the final output would be as follows:
names[0] = aaxyz
names[1] = bbxyz
names[2] = ccxyz
Any suggestions.
This can be done quite simply using a Select:
This will create a list of string with “yz” appended to each. If you then want to concatenate into a single string, you can use a Linq aggregate:
However, personally, I would use a foreach and StringBuilder in this context. More readable and better performance!