■ Enumerable 클래스의 Select<TSource, TResult> 확장 메소드를 사용하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
using System; using System.Collections.Generic; using System.Linq; /// <summary> /// 임직원 /// </summary> class Employee { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 성명 - Name /// <summary> /// 성명 /// </summary> public string Name { get; set; } #endregion #region 부서 - Department /// <summary> /// 부서 /// </summary> public string Department { get; set; } #endregion #region 취미 배열 - HobbyArray /// <summary> /// 취미 배열 /// </summary> public string[] HobbyArray { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Public #region 임직원 리스트 구하기 - GetEmployeeList() /// <summary> /// 임직원 리스트 구하기 /// </summary> /// <returns>임직원 리스트</returns> public static List<Employee> GetEmployeeList() { List<Employee> employeeList = new List<Employee> { new Employee { Name = "홍길동", Department = "영업부" , HobbyArray = new string[] { "게임", "독서" }}, new Employee { Name = "황희" , Department = "경리부" , HobbyArray = new string[] { "수영", "영화감상" }}, new Employee { Name = "정약용", Department = "신사업기획부", HobbyArray = new string[] { "등산", "DIY" }} }; return employeeList; } #endregion } ... List<Employee> employeeList = Employee.GetEmployeeList(); var result = employeeList.Select(employee => employee.HobbyArray); foreach(string[] hobbyArray in result) { foreach(string hobby in hobbyArray) { Console.WriteLine(hobby); } } /* 게임 독서 수영 영화감상 등산 DIY */ |