C#Linq SelectMany方法
使用SelectMany方法可将元素折叠到单个集合中,例如出现错误。
一个示例是将字符串转换为字符数组。以下是我们的字符串数组。
string[] str = { "Mobile", "Laptop", "Tablet" };现在,转换为字符数组。
str.SelectMany(item => item.ToCharArray());
示例
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
string[] str = { "Mobile", "Laptop", "Tablet" };
var res = str.SelectMany(item => item.ToCharArray());
Console.WriteLine("String converted to character array: ");
foreach (char letter in res) {
Console.Write(letter);
}
}
}输出结果
String converted to character array: MobileLaptopTablet
热门推荐
9 送心的祝福语简短
10 英语祝福语大全简短母亲
11 晚辈给长辈祝福语简短
12 毕业教师花语祝福语简短
13 吃饭后祝福语2026简短
14 谢谢同事英文祝福语简短
15 祝福语送顾客简短语
16 节日祝福语大全简短创意
17 古风祝福语 唯美简短结婚
18 结婚伴娘祝福语简短精辟