CKTIS / C#
get: referencia práctica
get: referencia práctica: get lee el valor de una property o indexer y puede ejecutar código.
Versión: C# language; verified against C# 14 reference
Sintaxis
get /* grammar-specific form */get lee el valor de una property o indexer y puede ejecutar código.
Úsalo para lecturas controladas manteniendo el getter rápido y previsible.
Un getter puede lanzar una excepción o hacer I/O aunque el usuario espere leer un campo.
Una property puede tener get sin set y menor visibilidad del accesor.
El programa completo usa realmente get; su stdout esperado exacto es 8.
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;
Console.WriteLine(new Sample().Value);
sealed class Sample { public int Value { get => 8; } }
Resultado
8
El programa completo usa realmente `get`; su stdout esperado exacto es `8`.