726bb56d3f1d0365ed904c818b699779
49.ToList

LINQ ToList 简介

从 IEnumerable 创建一个 List

LINQ ToList 示例代码

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

using System.Linq;
using UnityEngine;

namespace UniRxLesson
{
    public class LINQToListExample : MonoBehaviour
    {
        private void Start()
        {
            string[] fruits = { "apple", "passionfruit", "banana", "mango", 
                "orange", "blueberry", "grape", "strawberry" };

            var lengths = fruits.Select(fruit => fruit.Length).ToList();

            Debug.Log(lengths.GetType());

            foreach (var length in lengths)
            {
                Debug.Log(length);
            }
        }
    }
}

输出结果:

System.Collections.Generic.List`1[System.Int32]
5
12
6
5
6
9
5
10

UniRx ToList 示意图

top Created with Sketch.