■ Enumerable 클래스의 TakeWhile<T> 확장 메소드를 사용해 지정된 조건이 true인 동안 시퀀스에서 요소를 구하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using System; using System.Collections.Generic; using System.Linq; IList<string> stringList = new List<string>() { "One", "Two", "Three", "Four", "Five", "Six" }; IEnumerable<string> resultEnumerable = stringList.TakeWhile((source, index) => source.Length > index); foreach(string source in resultEnumerable) { Console.WriteLine(source); } |