public class FileLoader
{
public delegate void FileLoadHandler(int progress);
public FileLoadHandler FileLoaded;
public void UpLoad()
{
int fileProgress = 100;
while (fileProgress>0)
{
fileProgress--;
if (FileLoaded!=null)
{
FileLoaded(fileProgress);
}
}
}
}
public class TestFileLoader
{
public static void Run()
{
FileLoader fl = new FileLoader();
fl.FileLoaded = Proress;
fl.UpLoad();
}
//为何必须为static?
private void Proress(int progress)
{
Console.WriteLine(progress);
}
如何方法Proress(int progress)不设置为static系统就报出:An object reference is required for the non-static field, method, or property?。这是什么原因?难不成是代理的对象引用必须为静态方法?
因为它是在静态方法run中被调用的。