代码
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
// 创建包含多个子列表的List<List<int>>对象
var nestedList = new List<List<int>>()
{
new List<int>(){1,2,3},
new List<int>(){4,5,6}
};
// 使用LINQ查询将所有元素合并到单个的List<int>中
var flattenedList = nestedList.SelectMany(list => list).ToList();
// 输出结果
foreach (var item in flattenedList)
{
Console.WriteLine(item);
}
}
}
网友评论