Select 메서드를 사용하여 배열의 요소를 수정합니다.
다음은 문자열 배열입니다.
string[] stationery = { "diary", "board", "pencil", "whiteboard" }; Select 메서드는 또한 아래와 같이 Lambda 식을 지정합니다 -
예
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
public static void Main() {
string[] stationery = { "diary", "board", "pencil", "whiteboard" };
var res = stationery.AsQueryable().Select((item, index) => new { result = item.Substring(0, index + 4) });
foreach (var str in res) {
Console.WriteLine("{0}", str);
}
}
} 출력
{ result = diar }
{ result = board }
{ result = pencil }
{ result = whitebo }