c#集合中的集合的处理方式

foreach里面嵌套select

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<List<string>> lst = new List<List<string>>();
            for (int i = 0; i < 10; i++)
            {
                List<string> t = new List<string>();
                t.Add("a" + i.ToString());
                t.Add("b" + i.ToString());
                t.Add("c" + i.ToString());
                lst.Add(t);
            }
            List<string> temp = new List<string>();
            lst.ForEach(s =>
            {
                temp.AddRange(s.Select(t => t.ToString()).ToList());

            });
        }
    }
}

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/115265973