Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

in: practical reference

in: practical reference: in denotes an input by readonly reference or, in query syntax, binds a range variable to a source; it is not a membership operator.

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

Syntax

in /* grammar-specific form */

in denotes an input by readonly reference or, in query syntax, binds a range variable to a source; it is not a membership operator.

Use it for large structs when measurement confirms a benefit from avoiding copies.

The compiler may create a defensive copy when a seemingly readonly member is invoked.

Depending on explicit or implicit in syntax, the argument may be a variable or temporary value.

The complete program actually uses in; its exact expected stdout is 9.

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;

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

Result

9

The complete program actually uses `in`; its exact expected stdout is `9`.

Sources