CKTIS / C#
private: riferimento pratico
private: riferimento pratico: private limita l’accesso al tipo contenitore.
Versione: C# language; verified against C# 14 reference
Sintassi
private /* grammar-specific form */private limita l’accesso al tipo contenitore.
Usalo per impostazione predefinita per dettagli implementativi e protezione degli invarianti.
Reflection può accedervi, quindi private non è un confine di sicurezza.
Un tipo annidato ha diritti di accesso speciali al tipo contenitore.
Il programma completo usa realmente private; lo stdout esatto atteso è 3.
Esempi
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 Box().Read());
sealed class Box { private readonly int value = 3; public int Read() => value; }
Risultato
3
Il programma completo usa realmente `private`; lo stdout esatto atteso è `3`.