views:

750

answers:

2

I see this line in many online examples of using the Action delegate:

public event Action MyEvent;

But when I try it in my own code, I get this the error

Using the generic type 'System.Action' requires '1' type arguments

The documentation certainly describes a form of Action without any type parameter. What am I missing?

+5  A: 

Make sure your application is referencing System.Core.

Edit - also make sure you are targeting .NET 3.5 as the System.Core.dll is part of that version.

Andrew Hare
And is .NET 3.5...
Simon Buchan
Thanks! I did not have a System.Core reference.Even knowing the answer, I still could not find it in the docs.
I. J. Kennedy
+5  A: 

Expanding on Andrews answer.

It's perfectly legal to use Action in a non-3.5 scenario. Simply define it yourself.

public delegate void Action();
JaredPar
+1 very good point.
Andrew Hare
Unless you are passing it to someone elses library, that is using System.Core's Action...
Simon Buchan
@Simon, in that case you must already be using 3.5 (directly or indirectly) so it's not an issue.
JaredPar