本文介绍了C#性能3中的并行For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 有人能给我看一个获取列表的例子,使用并行for循环对列表'属性中的每个元素进行一些操作然后返回原始列表吗?例如Can anyone show me an example of taking a list, doing some operation in each element in the list''s property using a parallel for loop and then returning the original list? For exampleList<t> someList = new List<t>for(int i= 0; i < originallist.count;i++){ Do operation on originallist[i].somevariable someList.add(originallist[i])}return someList 换句话说。我将如何并行化这个???In other words. HOW would I parallelize this???推荐答案static void MultiplyMatricesParallel(double[,] matA, double[,] matB, double[,] result){ int matACols = matA.GetLength(1); int matBCols = matB.GetLength(1); int matARows = matA.GetLength(0); // A basic matrix multiplication. // Parallelize the outer loop to partition the source array by rows. Parallel.For(0, matARows, i => { for (int j = 0; j < matBCols; j++) { // Use a temporary to improve parallel performance. double temp = 0; for (int k = 0; k < matACols; k++) { temp += matA[i, k] * matB[k, j]; } result[i, j] = temp; } }); // Parallel.For} b $ b 亲切的问候,Kind regards, 这篇关于C#性能3中的并行For循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!