Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

void: practical reference

void: practical reference: void states that a method or delegate returns no value.

Version: C# language; verified against C# 14 reference

Syntax

void /* grammar-specific form */

void states that a method or delegate returns no value.

Use it for commands whose outcome is expressed by an effect or exception.

Reserve async void for event handlers because it supplies no Task for awaiting or error handling.

A void method can still use return without an expression and can throw exceptions.

The complete program actually uses void; its exact expected stdout is done.

Examples

using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;

Write(); static void Write() => Console.WriteLine("done");

Result

done

The complete program actually uses `void`; its exact expected stdout is `done`.

Sources