Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C# Linq SelectMany Method
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
Advertisements