解决方案 »

  1.   

    void Main()
    {
    List<List<string>> proplist = new List<List<string>>(); proplist.Add(new List<string>(){"a","b","r"});
    proplist.Add(new List<string>() { "c", "d","h" });
    proplist.Add(new List<string>() { "e", "f","y" });[code=csharp]

    var q=from a in proplist.First()
      from b in proplist.Skip(1).First()
      from c in proplist.Skip(2).First() 
      select string.Format("{0}{1}{2}",a,b,c);
      
    q.ToList().ForEach(x=>Console.WriteLine(x));
    }[/code][code=csharp]void Main()
    {
    List<List<string>> proplist = new List<List<string>>(); proplist.Add(new List<string>(){"a","b","r"});
    proplist.Add(new List<string>() { "c", "d","h" });
    proplist.Add(new List<string>() { "e", "f","y" });[code=csharp]acf
    acy
    ade
    adf
    ady
    ahe
    ahf
    ahy
    bce
    bcf
    bcy
    bde
    bdf
    bdy
    bhe
    bhf
    bhy
    rce
    rcf
    rcy
    rde
    rdf
    rdy
    rhe
    rhf
    rhy [/code]
      

  2.   

    void Main()
    {
    List<List<string>> proplist = new List<List<string>>(); proplist.Add(new List<string>(){"a","b","r"});
    proplist.Add(new List<string>() { "c", "d","h" });
    proplist.Add(new List<string>() { "e", "f","y" });

    var q=from a in proplist.First()
      from b in proplist.Skip(1).First()
      from c in proplist.Skip(2).First() 
      select string.Format("{0}{1}{2}",a,b,c);
      
    q.ToList().ForEach(x=>Console.WriteLine(x));
    }ace
    acf
    acy
    ade
    adf
    ady
    ahe
    ahf
    ahy
    bce
    bcf
    bcy
    bde
    bdf
    bdy
    bhe
    bhf
    bhy
    rce
    rcf
    rcy
    rde
    rdf
    rdy
    rhe
    rhf
    rhy
      

  3.   

     
                var m = proplist.Aggregate(Enumerable.Repeat("", 1),
                    (current, item) => current.SelectMany(n => item, (a, b) => a + b));            foreach (var item in m)
                {
                    Console.WriteLine(item);
                }
      

  4.   

    首先,感谢版主回复啊,你这个代码有个问题啊
    就是我的proplist的item是动态添加的,不是固定只有3个的
      

  5.   

    你的需求是对proplist的元素依次做迪卡尔积看到涉及迪卡尔积的,考虑SelectMany的带选择器版本;
    看到需要依次处理的,考虑Aggregate
      

  6.   

    http://hi.baidu.com/qxyywy/item/49e8c7f72a019ad86325d238
      

  7.   


            protected void Page_Load(object sender, EventArgs e)
            {
                List<List<string>> proplist = new List<List<string>>();            proplist.Add(new List<string>() { "a", "b", "r" });
                proplist.Add(new List<string>() { "c", "d", "h" });
                proplist.Add(new List<string>() { "e", "f", "y" });
                var a = AAAAA(proplist);
                foreach (var temp in a)
                {
                    Response.Write(temp + "<br/>");
                }
            }
            public IEnumerable<string> AAAAA(List<List<string>> list)
            {
                IEnumerable<string> result = list.First();
                for (int i = 1; i < list.Count; i++)
                {
                    int index = i;
                    result = result.SelectMany(x => list[index].Select(y => y + x));
                }
                return result;
            }
    多少个都行
      

  8.   

    来一个递归版本的.
    List<string> res = MergeList(proplist).ToList();private IEnumerable<string> MergeList(List<List<string>> proplist)
    {
        if (proplist.FirstOrDefault() == null)
            return new List<string>() { "" };
        var divs = proplist.Where(c => c != proplist.FirstOrDefault()).ToList();
        return from a in proplist.First() from b in MergeList(divs) select string.Format("{0}{1}", a, b);
    }