Base de conocimientosCentro de exámenes
ESEspañol
Elegir idioma13

CKTIS / C#

public: referencia práctica

public: referencia práctica: public expone un tipo o miembro a todo consumidor permitido por su tipo contenedor.

Versión: C# language; verified against C# 14 reference

Sintaxis

public /* grammar-specific form */

public expone un tipo o miembro a todo consumidor permitido por su tipo contenedor.

Úsalo solo para una API estable y documentada.

Cada miembro public aumenta el coste de compatibilidad y la superficie de seguridad.

Un miembro public de un tipo internal no es accesible fuera del assembly.

El programa completo usa realmente public; su stdout esperado exacto es 6.

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 PublicType().Value);
public sealed class PublicType { public int Value => 6; }

Resultado

6

El programa completo usa realmente `public`; su stdout esperado exacto es `6`.

Fuentes