gpt4 book ai didi

c# - 请求一个 linq 来操作数组的数组

转载 作者:行者123 更新时间:2023-11-30 19:46:24 26 4
gpt4 key购买 nike

我有一个包含以下元素的数组

{Mark=90, Students={"Tom","Marry","Jack"}},
{Mark=50, Students={"Niko","Gary","David"}},
{Mark=70, Students={"John","Andy","Amy"}}

我想要一个 Linq 语句将它们转换成

{Mark=90, name="Tom"},
{Mark=90, name="Marry"},
{Mark=90, name="Jack"},
{Mark=50, name="Niko"},
{Mark=50, name="Gary"},
{Mark=50, name="David"},
{Mark=70, name="John"},
{Mark=70, name="Andy"},
{Mark=70, name="Amy"}

我该怎么办?

最佳答案

您可以转换到匿名类(如果您需要当前方法之外的序列,则可以转换到真实类):

var results = from x in myArray
from s in x.Students
select new { x.Mark, name = s };

关于c# - 请求一个 linq 来操作数组的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8625180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com