8b4f4eaf9337242c9648e55b4f12a99c
35.Concat

LINQ Concat 简介

连接两个序列。

LINQ Concat 示例代码

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

using System.Linq;
using UnityEngine;

namespace UniRxLesson
{
    public class LINQConcatExample : MonoBehaviour
    {
        private class Pet
        {
            public string Name { get; set; }
            public int    Age  { get; set; }
        }

        private void Start()
        {
            Pet[] cats =
            {
                new Pet {Name = "Barley", Age = 8},
                new Pet {Name = "Boots", Age = 4},
                new Pet {Name = "Whiskers", Age = 1}
            };

            Pet[] dogs =
            {
                new Pet {Name = "Bounder", Age = 3},
                new Pet {Name = "Snoopy", Age = 14},
                new Pet {Name = "Fido", Age = 9}
            };

            var petNames =
                cats.Select(cat => cat.Name).Concat(dogs.Select(dog => dog.Name));

            foreach (var petName in petNames)
            {
                Debug.Log(petName);
            }
        }
    }
}

输出结果:

```cs
Barley
Boots
Whiskers
Bounder

top Created with Sketch.