Use SelectMany method to collapse elements into a single collection like an error.
An example would be to convert string to character array. The following is our string array.
string[] str = { "Mobile", "Laptop", "Tablet" };Now, convert to character array.
str.SelectMany(item => item.ToCharArray());
Example
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);
}
}
}Output
String converted to character array: MobileLaptopTablet