首页 新闻 会员 周边

An object reference is required for the non-static field, method, or property?

0
[已关闭问题] 关闭于 2012-07-30 11:55

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?。这是什么原因?难不成是代理的对象引用必须为静态方法?

c#
viola的主页 viola | 菜鸟二级 | 园豆:211
提问于:2012-02-10 08:41
< >
分享
所有回答(1)
0

因为它是在静态方法run中被调用的。

viola | 园豆:211 (菜鸟二级) | 2012-07-30 11:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册