CKTIS / C#
protected: praktická reference
protected: praktická reference: protected zpřístupňuje člen jeho typu a odvozeným třídám přes vhodný přijímač.
Verze: C# language; verified against C# 14 reference
Syntaxe
protected /* grammar-specific form */protected zpřístupňuje člen jeho typu a odvozeným třídám přes vhodný přijímač.
Použijte pro řízené rozšiřovací body v záměrně navržené hierarchii.
Rozšiřuje plochu kompatibility téměř jako public a později se těžko odebírá.
protected internal a private protected dávají přístup různým množinám volajících.
Úplný program skutečně používá protected; přesně očekávaný stdout je 5.
Příklady
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 Child().Read());
class Parent { protected int Value => 5; } sealed class Child : Parent { public int Read() => Value; }
Výsledek
5
Úplný program skutečně používá `protected`; přesně očekávaný stdout je `5`.