Reputation: 18547
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
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