47b724176aafda2839ff119edd07298e
42.TakeWhile

LINQ TakeWhile 简介

如果指定的条件为 true,则返回序列中的元素,然后跳过剩余的元素。

LINQ TakeWhile 示例代码

/****************************************************************************
 * http://sikiedu.com liangxie
 ****************************************************************************/

using System.Linq;
using UnityEngine;

namespace UniRxLesson
{
    public class LINQTakeWhileExample : MonoBehaviour
    {
        private void Start()
        {
            var fruits = new[]
            {
                "apple", "banana", "mango", "orange",
                "passionfruit", "grape"
            };

            var fruitsAfterOrange =
                fruits.TakeWhile(fruit => fruit != "orange");

            foreach (var fruit in fruitsAfterOrange)
            {
                Debug.Log(fruit);
            }
        }
    }
}

输出结果为

```cs
apple

top Created with Sketch.