CKTIS / C#
return: referencia práctica
return: referencia práctica: return termina una función y puede entregar un resultado al llamador.
Versión: C# language; verified against C# 14 reference
Sintaxis
return /* grammar-specific form */return termina una función y puede entregar un resultado al llamador.
Usa return anticipado para simplificar las cláusulas de guarda y la ruta principal.
El código tras un return incondicional es inalcanzable, aunque finally sí se ejecuta.
Un método async que devuelve Task o Task comunica la finalización o el resultado mediante ese Task; async también puede devolver void, un tipo task-like adecuado como ValueTask o ValueTask, o IAsyncEnumerable en un iterador async. Un iterador normal no puede usar return con un valor.
El programa completo usa realmente return; su stdout esperado exacto es 8.
Ejemplos
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;
Console.WriteLine(Double(4)); static int Double(int value) { return value * 2; }
Resultado
8
El programa completo usa realmente `return`; su stdout esperado exacto es `8`.