E595d4430ad18519a73112007cd7c1dc
51.Empty

LINQ Empty 简介

返回具有指定类型参数的空 IEnumerable\

LINQ Empty 示例代码

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

using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace UniRxLesson
{
    public class LINQEmptyExample : MonoBehaviour
    {
        private void Start()
        {
            string[] names1 = { "Hartono, Tommy" };
            string[] names2 = { "Adams, Terry", "Andersen, Henriette Thaulow",
                "Hedlund, Magnus", "Ito, Shu" };
            string[] names3 = { "Solanki, Ajay", "Hoeing, Helge",
                "Andersen, Henriette Thaulow",
                "Potra, Cristina", "Iallo, Lucio" };

            var namesList =
                new List<string[]> { names1, names2, names3 };

            var allNames =
                namesList.Aggregate(Enumerable.Empty<string>(),
                    (current, next) => next.Length > 3 ? current.Union(next) : current);

            foreach (var name in allNames)
            {
                Debug.Log(name);
            }
        }
    }
}

输出结果为:

top Created with Sketch.