为什么在使用Task时使用私有静态方法

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)

我不明白使用私有静态方法的目的,而不是任何其他正常的公共方法.

谢谢

slo*_*oth 5

该方法是静态的,因为它是从静态上下文中使用的,因此它不能是非静态的.

该方法可能是私有的,因为没有理由将其公开.