CKTIS / C#
private: практическа справка
private: практическа справка: private ограничава достъпа до съдържащия тип.
Версия: C# language; verified against C# 14 reference
Синтаксис
private /* grammar-specific form */private ограничава достъпа до съдържащия тип.
Използвайте по подразбиране за детайли на реализацията и защита на инварианти.
Reflection може да получи достъп, затова private не е граница за сигурност.
Вложен тип има специални права за достъп до съдържащия тип.
Пълната програма действително използва private; точният очакван stdout е 3.
Примери
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; }
Резултат
3
Пълната програма действително използва `private`; точният очакван stdout е `3`.