Why the order of LINQ to objects methods counts

前端 未结 5 2098
一整个雨季
一整个雨季 2021-02-14 15:58

I read this question\'s answers that explain the order of the LINQ to objects methods makes a difference. My question is why?

If I write a LINQ to SQL query, it doesn\'t

5条回答
  •  隐瞒了意图╮
    2021-02-14 16:50

    It's perfectly legal to use side-effecting operations. Compare:

    "crabapple"
        .OrderBy(c => { Console.Write(c); return c; })
        .Where(c => { Console.Write(c); return c > 'c'; })
        .Count();
    "crabapple"
        .Where(c => { Console.Write(c); return c > 'c'; })
        .OrderBy(c => { Console.Write(c); return c; })
        .Count();
    

提交回复
热议问题