CKTIS / C#
get: odniesienie praktyczne
get: odniesienie praktyczne: get odczytuje wartość property lub indexer i może zawierać kod.
Wersja: C# language; verified against C# 14 reference
Składnia
get /* grammar-specific form */get odczytuje wartość property lub indexer i może zawierać kod.
Stosuj do kontrolowanego odczytu, utrzymując getter szybki i bez zaskakujących efektów.
Getter może rzucać i wykonywać I/O, choć użytkownik oczekuje odczytu pola.
Właściwość może mieć get bez set; dostępność akcesora może być węższa.
Kompletny program rzeczywiście używa get; oczekiwany stdout to dokładnie 8.
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(new Sample().Value);
sealed class Sample { public int Value { get => 8; } }
Wynik
8
Kompletny program rzeczywiście używa `get`; oczekiwany stdout to dokładnie `8`.