void

suggest change

The reserved word "void" is an alias of System.Void type, and has two uses:

  1. Declare a method that doesn’t have a return value:
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.
}
  1. Declare a pointer to an unknown type in an unsafe context.

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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents