language: C# (mono-2.8)
date: 612 days 11 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.Collections.Generic;
using System.Linq;
 
public class Test
{
        static IEnumerable<string> MultiConcat(params IEnumerable<string>[] lists)
        {
            if (lists == null) {
                return null;
            }
        
            if (lists.Length == 0) {
                return Enumerable.Empty<string>();
            }
        
            return lists.Aggregate(new[] { string.Empty } as IEnumerable<string>,
                           (acc, list) => acc.SelectMany(s1 => list.Select(s2 => s1 + s2)));
        }
 
        public static void Main()
        {
                var list1 = new List<string> { "A", "B" };
                var list2 = new List<string> { "1", "2", "3" };
                var list3 = new List<string> { "FOO", "BAR" };
                
                foreach (var s in MultiConcat(list1, list2, list3)) {
                    Console.Out.WriteLine(s);
                }               
        }
}