简体   繁体   中英

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?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM