[英]What is the easiest way to append a string
Say I have a function List<string> list
with content {"a","b","c","d"}
假设我有一个包含内容
{"a","b","c","d"}
的函数List<string> list
is it possible to have a return statement like 是否有可能有一个返回语句
return list union {"d"}
//Which is essentially {"a","b","c","d","d"}
return list union {"d"}
//本质上是{"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
. 此语句不会更改
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: Concat
方法是LINQ提供的扩展方法,因此请确保在文件顶部using
以下using
语句:
using System.Linq;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.