簡體   English   中英

附加字符串的最簡單方法是什么?

[英]What is the easiest way to append a string

假設我有一個包含內容{"a","b","c","d"}的函數List<string> list

是否有可能有一個返回語句

return list union {"d"} //本質上是{"a","b","c","d","d"}

如果是的話語法是什么?

是:

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

此語句不會更改list內容。 Concat方法是LINQ提供的擴展方法,因此請確保在文件頂部using以下using語句:

using System.Linq;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM