额,自行领悟何谓递归ps:就你的问题本身,请google“c# 笛卡尔积”

解决方案 »

  1.   

    类似这个
    http://bbs.csdn.net/topics/390550326?page=1#post-395315031
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int[][] data = new int[][] 
                { 
                    new int[] { 1, 2, 3 },
                    new int[] { 4, 5 },
                    new int[] { 7, 8 },
                    new int[] { 9 }
                };
                var query = data[0].Select(x => new int[] { x });
                foreach (var item in data.Skip(1))
                {
                    query = query.SelectMany(x => item.Select(y => x.Concat(new int[] { y }).ToArray()));
                }
                foreach (var item in query)
                {
                    Console.WriteLine(string.Join(", ", item));
                }
            }
        }
    }1, 4, 7, 9
    1, 4, 8, 9
    1, 5, 7, 9
    1, 5, 8, 9
    2, 4, 7, 9
    2, 4, 8, 9
    2, 5, 7, 9
    2, 5, 8, 9
    3, 4, 7, 9
    3, 4, 8, 9
    3, 5, 7, 9
    3, 5, 8, 9
    Press any key to continue . . .
      

  3.   

    open System.Linq[<EntryPoint>]
    let main argv =
        begin
        let data =     
            [|
                [| 1; 2; 3 |]
                [| 4; 5 |]
                [| 7; 8 |]
                [| 9 |]
            |]
        let mutable query = data.[0].Select(fun x -> [| x |])
        for item in data.Skip(1) do
            query <- query.SelectMany(fun (x:int[]) -> item.Select(fun y -> x.Concat([| y |]).ToArray()))
        for item in query do
            printfn "%s" ((Array.fold(fun acc elem -> acc + elem.ToString() + ", ") "" (item)).TrimEnd(',', ' '))
        0
        end1, 4, 7, 9
    1, 4, 8, 9
    1, 5, 7, 9
    1, 5, 8, 9
    2, 4, 7, 9
    2, 4, 8, 9
    2, 5, 7, 9
    2, 5, 8, 9
    3, 4, 7, 9
    3, 4, 8, 9
    3, 5, 7, 9
    3, 5, 8, 9
    Press any key to continue . . .
      

  4.   

    转成递归,写法很简洁
    参考:http://jingyan.baidu.com/article/046a7b3efb6f5df9c27fa9ec.html
      

  5.   


    copy代码运行 完全错误