C# program to demonstrate the example of SelectMany() method in LINQ
//C# program to demonstrate the
//SelectMany() method in Linq.
using System;
using System.Collections.Generic;
using System.Linq;
public class Employee
{
public int ID;
public string Name;
public List<string> Skills;
public static List<Employee> GetEmpDetails()
{
return new List<Employee>()
{
new Employee(){ID = 101, Name = "Amit", Skills = new List<string>() { "C", "C++", "DS"} },
new Employee(){ID = 102, Name = "Sumit", Skills = new List<string>() { "C#", "VB" }},
new Employee(){ID = 103, Name = "Patriq", Skills = new List<string>() { "JAVA","JSP","Servlet"} },
new Employee(){ID = 104, Name = "Arun", Skills = new List<string>() { "ADO.NET", "OLEDB", "ODBC" } }
};
}
static void Main(string[] args)
{
List<string> skill_list = Employee.GetEmpDetails().SelectMany(emp => emp.Skills).ToList();
foreach (string skill in skill_list)
{
Console.Write(skill+" ");
}
Console.WriteLine();
}
}
Output
C C++ DS C# VB JAVA JSP Servlet ADO.NET OLEDB ODBC
Press any key to continue . . .
Table of Contents