LINQ equivalent of foreach for IEnumerable

后端 未结 22 2556
夕颜
夕颜 2020-11-21 22:54

I\'d like to do the equivalent of the following in LINQ, but I can\'t figure out how:

IEnumerable items = GetItems();
items.ForEach(i => i.DoS         


        
22条回答
  •  野性不改
    2020-11-21 23:30

    There is an experimental release by Microsoft of Interactive Extensions to LINQ (also on NuGet, see RxTeams's profile for more links). The Channel 9 video explains it well.

    Its docs are only provided in XML format. I have run this documentation in Sandcastle to allow it to be in a more readable format. Unzip the docs archive and look for index.html.

    Among many other goodies, it provides the expected ForEach implementation. It allows you to write code like this:

    int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8 };
    
    numbers.ForEach(x => Console.WriteLine(x*x));
    

提交回复
热议问题