[닷넷C#링크]메소드쿼리식,Select,SelectMany의차이
꽁스짱
C#
0
1077
2021.02.15 23:19
[닷넷C#링크]메소드쿼리식,Select,SelectMany의차이
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Select : 하나의 Collection에서 Select
//SelectMany : 다중 Collection에서 Select
namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
var nameList = new List<string>
{
"SCOTT",
"SMITH",
"FORD",
"ALLEN",
"ADAM",
"JOHNS",
"CHRISMA",
"NANAMONO"
};
var names1 = nameList
.Where( n => n.StartsWith("S"))
.Select(n => n).ToList();
names1.ForEach(n => Console.WriteLine(n));
Console.WriteLine();
var names2 = nameList
.Where(n => n.StartsWith("S"))
.SelectMany(n => n).ToList();
names2.ForEach(n => Console.WriteLine(n));
}
}
}
[결과]
SCOTT
SMITH
S
C
O
T
T
S
M
I
T
H