CKTIS / C#
get: referência prática
get: referência prática: get lê o valor de uma property ou indexer e pode executar código.
Versão: C# language; verified against C# 14 reference
Sintaxe
get /* grammar-specific form */get lê o valor de uma property ou indexer e pode executar código.
Usa-o para leituras controladas, mantendo o getter rápido e previsível.
Um getter pode lançar uma exceção ou fazer I/O embora pareça uma leitura de campo.
Uma property pode ter get sem set e visibilidade mais restrita do accessor.
O programa completo usa realmente get; o stdout exato esperado é 8.
Exemplos
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; } }
Resultado
8
O programa completo usa realmente `get`; o stdout exato esperado é `8`.