日期:2014-05-20  浏览次数:20742 次

ling中,sql写法的"Let"关键字,用lambda如何表示?
比如
static void Main(string[] args)
{
    string[] strings=
    {
        "A penny saved is a penny earned.",
        "The aaxly sdj",
        "the pa is no"
    };

    var query =
                from sentence in strings
                let words = sentence.Split(' ')//用空格分割成数组
                from word in words
                let w = word.ToLower()//把每个字母小写
                where w[0] == 'a' || w[0] == 'e'
                select word;
    foreach (var s in query)
    {
        Console.WriteLine(s);
    }
    Console.ReadLine();
}

 

我试着用lambda写法写了下,在let这里遇到困难了?其中需要降维,用select貌似搞不定啊.

------解决方案--------------------
引用:
好吧,果然一发帖,又找到方法了...
自结:

 var query2 =
                strings.Select(a => a.Split(' '))
                    .SelectMany(b => b.Where(c => c.ToLower()[0] == 'a' 
------解决方案--------------------
 c.ToLower()[0] == 'e'));

分不给一楼,谁来接分!!!

我来了。。。。。。
顺便告诉你,是表达式翻译成sql语句,然后发给sql引擎进行的查询。