/// <summary>
/// Parallel.For
/// Parallel.ForEach
/// 并行循环,迭代之间互相独立,程序运行在多核处理器上,能并行处理,提高效率
/// </summary>
class Program
{
static void Main(string[] args)
{
Parallel.For(0, 15, i => Console.WriteLine("The square of {0} is {1}", i, i * i));
const int maxValues = 50;
int[] squares = new int[maxValues];
Parallel.For(0, maxValues,i=>squares[i]=i*i);
string[] squareStr = new string[]{ "We","hold","truths","to","be"};
//Parallel.ForEach(squareStr,i=>Console.WriteLine(string.Format("{0} has {1} letters",object,i.Length)));
Console.ReadKey();
}
}
/// Parallel.For
/// Parallel.ForEach
/// 并行循环,迭代之间互相独立,程序运行在多核处理器上,能并行处理,提高效率
/// </summary>
class Program
{
static void Main(string[] args)
{
Parallel.For(0, 15, i => Console.WriteLine("The square of {0} is {1}", i, i * i));
const int maxValues = 50;
int[] squares = new int[maxValues];
Parallel.For(0, maxValues,i=>squares[i]=i*i);
string[] squareStr = new string[]{ "We","hold","truths","to","be"};
//Parallel.ForEach(squareStr,i=>Console.WriteLine(string.Format("{0} has {1} letters",object,i.Length)));
Console.ReadKey();
}
}