william007
william007

Reputation: 18547

What is the easiest way to append a string

Say I have a function List<string> list with content {"a","b","c","d"}

is it possible to have a return statement like

return list union {"d"} //Which is essentially {"a","b","c","d","d"}

if yes what is the syntax?

Upvotes: 0

Views: 79

Answers (1)

Sina Iravanian
Sina Iravanian

Reputation: 16296

Yes:

return list.Concat(new[] {"d"}).ToList();

This statement does not alter contents of list. The Concat method, is an extension method provided by LINQ, so make sure you have the following using statement on top of your file:

using System.Linq;

Upvotes: 2

Related Questions