LINQ side effects

后端 未结 5 1489
别那么骄傲
别那么骄傲 2020-12-11 02:43

is it possible to substitute a foreach loop with a lambda expression in LINQ (.Select))?

List l = {1, 2, 3, 4, 5};
forea         


        
5条回答
  •  暖寄归人
    2020-12-11 03:32

    For any IEnumerable, you can do:

    items.Any(item =>
    {
        Console.WriteLine(item);
        return false;
    }
    

    But this would be utterly wrong! It's like using a shoe to hammer the nail. Semantically, it does not make sense.

提交回复
热议问题