数据如下
一、1 2 3 44
二、a b c d
三、e f现在要写一个循环
1ae,1af,1be,1bf...............问题是,行数是未知的,可能是三行也可以是十行。

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<List<string>> list = new List<List<string>>()
                {
                    new List<string>() { "1", "2", "3", "44" },
                    new List<string>() { "a", "b", "c", "d" },
                    new List<string>() { "e", "f" }
                };
                var result = list.Aggregate((current, total) => total.Join(current, (string x) => 1, (string y) => 1, (string a, string b) => b + a).ToList());
                result.ForEach(x => { x.ToList().ForEach(y => Console.Write(y + " ")); Console.WriteLine(); });
            }
        }
    }
      

  2.   

     static void Main(string[] args)
            {
                List<string[]> list = new List<string[]>()
                {
                    new string[]{"1","2","3","44"},
                    new string[]{"a","b","c","d"},
                    new string[]{"e","f"}            };
                Fun(list, 0, "");
                Console.ReadLine();
            }
            static void Fun(List<string[]> list, int Row, string str)
            {
                if (Row == list.Count)
                    Console.WriteLine(str);
                if (Row < list.Count)
                {
                    for (int i = 0; i < list[Row].Length; i++)
                        Fun(list, Row + 1, str + list[Row][i]);
                }
            }
      

  3.   

     List<string[]> list = new List<string[]>()
                {
                    new string[]{"1","2","3","44"},
                    new string[]{"a","b","c","d"},
                    new string[]{"e","f"}            };
                Fun(list, 0, "");
                Console.ReadLine();
            }
            static void Fun(List<string[]> list, int Row, string str)
            {
                if (Row == list.Count)
                    Console.WriteLine(str);
                if (Row < list.Count)
                {
                    for (int i = 0; i < list[Row].Length; i++)
                        Fun(list, Row + 1, str + list[Row][i]);
                }
      

  4.   

    要点是linq的Aggregate汇总方法。你可以google/msdn它。
      

  5.   


    好强悍呀!! 菜鸟一枚, 第一个想到的就是三层循环,嘿嘿: List<List<string>> list = new List<List<string>>()  
     {                 
         new List<string>() { "1", "2", "3", "44" },     
         new List<string>() { "a", "b", "c", "d" },    
         new List<string>() { "e", "f" }             
     }; List<string> lstMsg = new List<string>();
     foreach (string str1 in list.ElementAt(0))
     {
         foreach (string str2 in list.ElementAt(1))
         {
             foreach (string str3 in list.Last())
             {
                 lstMsg.Add(String.Format("{0} - {1} - {2}", str1, str2, str3));
             }
         }
     } lstMsg.ForEach( x => Console.WriteLine(x) );Linq !!!