tags:

views:

98

answers:

1

Func<int, void> or Func<int, typeof(void)> seems to be not working.

Is it any way to solve this problem without delcaring custom delegates?

+10  A: 

void is not a data type in C#. You could use:

Action<int>

which is a delegate type for a method with a single int parameter and no return value.

Philippe Leybaert
Great! Thank you very much!
Overdose
C# void is an alias for the .NET Framework System.Void type.System.Void is a structure that specifies a return value type for a method that does not return a value.
Viktor Jevdokimov
System.Void is only useful if you're using reflection. It's not a real type, rather a placeholder to indicate "no return type"
Philippe Leybaert
Is it really not a real type? I know for sure `void` is a real type in the Common Type System, but it might not be the same as `System.Void`.
Joren
It depends what you call a real type. It would be interesting to see if you could define a variable of type void in the CLR. I doubt it though.
Philippe Leybaert
You cannot. Void is only usable as a return type. See my recent article on this for more details: http://blogs.msdn.com/ericlippert/archive/2009/06/29/the-void-is-invariant.aspx
Eric Lippert
Thanks for the clarification Eric.
Philippe Leybaert