首页 > 代码库 > Parallel for-each loops in .NET C# z

Parallel for-each loops in .NET C# z

  • An IEnumerable object
  • An Action of T which is used to process each item in the list
List<string> dataList = new List<string> 
{
         "this", "is", "random", "sentence", "hello", "goodbye"
};
 
Parallel.ForEach(dataList, item =>
{
    Console.WriteLine("Item {0} has {1} characters",
        item, item.Length);
});