Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any practical use of "Void" structure in .NET

Tags:

c#

.net

void

Just of a curiosity, is there any practical use of "Void" struct

except in Reflection ?

like image 943
kofucii Avatar asked Aug 26 '10 20:08

kofucii


2 Answers

System.Void is the equivalent of the void keyword. Check the tool tip of void and it will display

struct System.Void

But it can't be used directly in C#, so you best ignore it.

Trying to use System.Void will generate a compilation error

error CS0673: System.Void cannot be used from C# -- use typeof(void) to get the void type object

So then, it will fall to the topic of reflection only.

like image 65
Pierre-Alain Vigeant Avatar answered Oct 17 '22 21:10

Pierre-Alain Vigeant


I think, but I'm not sure, that this struct is used by the compiler to generate il for functions with void return type

like image 28
Arash Avatar answered Oct 17 '22 21:10

Arash