【发布时间】:2015-05-28 19:57:22
【问题描述】:
此代码取自另一个网站:
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
}
}
我不明白使用私有静态方法而不是任何其他普通公共方法的目的。
谢谢
【问题讨论】:
-
你说的是什么方法?
-
私有静态 Int32 Sum(Int32 n)
-
因为该方法仅适用于程序类,所以它是私有的