CKTIS / C#
out: odniesienie praktyczne
out: odniesienie praktyczne: out przekazuje parametr przez referencję; wywoływana metoda musi go definite assign przed normalnym return, a po przypisaniu może go odczytywać.
Wersja: C# language; verified against C# 14 reference
Składnia
out /* grammar-specific form */out przekazuje parametr przez referencję; wywoływana metoda musi go definite assign przed normalnym return, a po przypisaniu może go odczytywać.
Stosuj dla Try-pattern zwracającego bool i dodatkową wartość.
Wiele out pogarsza czytelność; rozważ tuple lub typ wyniku.
Przy false metoda nadal musi przypisać out, często default.
Kompletny program rzeczywiście używa out; oczekiwany stdout to dokładnie True\n7.
Przykłady
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(int.TryParse("7", out var value)); Console.WriteLine(value);
Wynik
True 7
Kompletny program rzeczywiście używa `out`; oczekiwany stdout to dokładnie `True\n7`.