void (c # 參考) void (C# reference)

您可以使用 void 做為 方法 的傳回類型 (或 區域函數) 來指定方法不會傳回值。You use void as the return type of a method (or a local function) to specify that the method doesn't return a value.

public static void Display(IEnumerable<int> numbers)
{
    if (numbers is null)
    {
        return;
    }

    Console.WriteLine(string.Join(" ", numbers));
}

您也可以使用 void 做為參考型別來宣告未知類型的指標。You can also use void as a referent type to declare a pointer to an unknown type. 如需詳細資訊,請參閱指標類型For more information, see Pointer types.

您無法使用 void 做為變數的類型。You cannot use void as the type of a variable.

另請參閱See also