The reserved word "void"
is an alias of System.Void
type, and has two uses:
public void DoSomething()
{
// Do some work, don't return any value to the caller.
}
A method with a return type of void can still have the return
keyword in its body. This is useful when you want to exit the method's execution and return the flow to the caller:
public void DoSomething()
{
// Do some work...
if (condition)
return;
// Do some more work if the condition evaluated to false.
}
In an unsafe context, a type may be a pointer type, a value type, or a reference type. A pointer type declaration is usually type* identifier
, where the type is a known type - i.e int* myInt
, but can also be void* identifier
, where the type is unknown.
Note that declaring a void pointer type is discouraged by Microsoft.