-3

I am trying Action<T,T> delegate and got the following error:

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

The event declaration looks as follows:

public event Action<string, string> FileStateProcess;

And the usage should looks like this:

if (FileStateProcess != null)
{
    FileStateProcess(file.FullName, temppath);
}

What am I doing wrong?

juharr
  • 31,741
  • 4
  • 58
  • 93
softshipper
  • 32,463
  • 51
  • 192
  • 400

1 Answers1

3

From your declaration we can see that the FileStateProcess action is non-static, so I assume the method from which you are calling it is a static method. In which case, remove the static keyword from the method and you should be good.

Alternatively, you can make FileStateProcess static, but this will mean that its value will be held in the actual type, rather than in an object instance.

public static event Action<string, string> FileStateProcess;

For more info, see:

Static Classes and Static Class Members (C# Programming Guide).

Y Ahmed
  • 46
  • 4