谁能帮忙吧这个方法改下,把LinQ改成平常的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (var item in foo(new List<Char>() { 'a', 'b' }, 6))
Console.WriteLine(item);
}
static IEnumerable<string> foo(List<char> metachars, int length)
{
if (length == 1) return metachars.Select(x => x.ToString());
return metachars.SelectMany(x => foo(metachars, length - 1).Select(y => y + x));
}
}
}
把上面的方法不用Linq,就平常的 递归调
谢谢 了
------解决方案--------------------更准确的说,那是Lamda
------解决方案--------------------using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
foreach (var item in foo(new List<Char>() { 'a', 'b', 'c' }, 4))
Console.WriteLine(item);
}
static IEnumerable<string> foo(List<char> metachars, int length)
{
if (length == 1)
foreach (char x in metachars)
yield return x.ToString();
else
foreach (char y in metachars)