Ton*_*ony -3 c# task-parallel-library
此代码取自其他网站:
using System;
using System.Threading.Tasks;
public class Program {
private static Int32 Sum(Int32 n)
{
Int32 sum = 0;
for (; n > 0; n--)
checked { sum += n; }
return sum;
}
public static void Main() {
Task<int32> t = new Task<int32>(n => Sum((Int32)n), 1000);
t.Start();
t.Wait();
// Get the result (the Result property internally calls Wait)
Console.WriteLine("The sum is: " + t.Result); // An Int32 value
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白使用私有静态方法的目的,而不是任何其他正常的公共方法.
谢谢
| 归档时间: |
|
| 查看次数: |
175 次 |
| 最近记录: |