本文整理匯總了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