Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

in: referencia práctica

in: referencia práctica: in indica una entrada por referencia readonly o, en la sintaxis query, liga una variable de rango a una fuente; no es un operador de pertenencia.

Versión: C# language; verified against C# 14 reference

Sintaxis

in /* grammar-specific form */

in indica una entrada por referencia readonly o, en la sintaxis query, liga una variable de rango a una fuente; no es un operador de pertenencia.

Úsalo para structs grandes cuando las mediciones confirmen el beneficio de no copiar.

El compilador puede crear una defensive copy al llamar a un miembro solo aparentemente readonly.

Según la forma explícita o implícita de in, el argumento puede ser variable o valor temporal.

El programa completo usa realmente in; su stdout esperado exacto es 9.

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;

var value = 9; Console.WriteLine(Read(in value)); static int Read(in int value) => value;

Resultado

9

El programa completo usa realmente `in`; su stdout esperado exacto es `9`.

Fuentes