简体   繁体   English

附加字符串的最简单方法是什么?

[英]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.

相关问题 格式化数字字符串的最简单方法是什么? - What's the easiest way to format a numeric string? 将MemoryStream中的RTF内容附加到XamRichTextEditor的最简单方法是什么 - What's the easiest way to append RTF content from a MemoryStream into an XamRichTextEditor 通过检查hiddenfields是否为空来附加具有不同值的字符串的最简单方法 - Easiest way to append a string with different values by checking if hiddenfields are empty 处理看起来像查询字符串的字符串最简单的方法是什么? - What's the easiest way to handle a string looking like a query string? 使用C#更改字符串中文本内容的最简单方法是什么? - What's the easiest way to change the contents of text in a string with C#? 如果长度改变,从字符串中获取某些值的最简单方法是什么? - What is the easiest way to get certain values from string if the length changes? 在C#中从bool转换为字符串的最简单方法是什么? - What's the easiest way to convert from a bool to string in C#? 检查字符串是否为空,不是空而不是=“0000”的最简单方法是什么? - What's the easiest way to check that a string is not null, not empty and not = “0000”? 循环输出string []的最简单方法是什么? - What's the easiest way to loop out values of string[]? 在C#中修剪字符串的换行符最简单的方法是什么? - What is the easiest way in C# to trim a newline off of a string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM