F9c41e3d21b60ca491d115fe54a34309
48.ToArray

LINQ ToArray 简介

从 IEnumerable\ 中创建数组。

LINQ ToArray 示例代码

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

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

namespace UniRxLesson
{
    public class LINQToArrayExample : MonoBehaviour
    {
        private class Package
        {
            public string Company { get; set; }
            public double Weight  { get; set; }
        }

        private void Start()
        {
            var packages =
                new List<Package>
                {
                    new Package {Company = "Coho Vineyard", Weight = 25.2},
                    new Package {Company = "Lucerne Publishing", Weight = 18.7},
                    new Package {Company = "Wingtip Toys", Weight = 6.0},
                    new Package {Company = "Adventure Works", Weight = 33.8}
                };

            var companies = packages.Select(pkg => pkg.Company).ToArray();

            foreach (var company in companies)
            {
                Debug.Log(company);
            }
        }
    }
}

输出结果:
```cs
Coho Vineyard
Lucerne Publishing
Wingtip Toys
Adventure Works

top Created with Sketch.