using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string[] metachars = { "1", "2" }; int n = 3; var result = metachars.AsEnumerable(); for (int i = 0; i < n - 1; i++) { result = result.SelectMany(x => metachars.Select(y => x + y)); } Console.WriteLine(string.Join("\r\n", result.ToArray())); } } }111 112 121 122 211 212 221 222 Press any key to continue . . .
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] metachars = { "1", "2" };
int n = 3;
var result = metachars.AsEnumerable();
for (int i = 0; i < n - 1; i++)
{
result = result.SelectMany(x => metachars.Select(y => x + y));
}
Console.WriteLine(string.Join("\r\n", result.ToArray()));
}
}
}111
112
121
122
211
212
221
222
Press any key to continue . . .