本文整理汇总了C#中System.Linq.Enumerable.ToArray<TSource>方法的典型用法代码示例。如果您正苦于以下问题:C# Enumerable.ToArray<TSource>方法的具体用法?C# Enumerable.ToArray<TSource>怎么用?C# Enumerable.ToArray<TSource>使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Enumerable.ToArray<TSource>方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToArrayEx1
class Package
{
public string Company { get; set; }
public double Weight { get; set; }
}
public static void ToArrayEx1()
{
List<Package> 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 } };
string[] companies = packages.Select(pkg => pkg.Company).ToArray();
foreach (string company in companies)
{
Console.WriteLine(company);
}
}
输出:
Coho Vineyard Lucerne Publishing Wingtip Toys Adventure Works