net 并行计算 学习 03 Parallel.ForEach


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForeachDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = new int[10];

            Parallel.For(0, nums.Length, (item) =>
            {
                //do logic
                var temp = nums[item];
            });

            Dictionary<int, int> dic = new Dictionary<int, int>()
            {
                {1,100},
                {2,200 },
                {3,300 }
            };

            Parallel.ForEach(dic, (item) =>
            {
                Console.WriteLine(item.Key);
            });
        }
    }
}



作者:spike

分类: Net

创作时间:2023-06-25

更新时间:2024-12-09

联系方式放在中括号之中例如[[email protected]],回复评论在开头加上标号例如:#1