CKTIS / C#
protected: praktična referenca
protected: praktična referenca: protected izpostavi član njegovemu tipu in izpeljanim razredom prek ustreznega prejemnika.
Različica: C# language; verified against C# 14 reference
Sintaksa
protected /* grammar-specific form */protected izpostavi član njegovemu tipu in izpeljanim razredom prek ustreznega prejemnika.
Uporabite za nadzorovane razširitvene točke v namensko zasnovani hierarhiji.
Razširi površino združljivosti skoraj kot public in ga je pozneje težko umakniti.
protected internal in private protected omogočata dostop različnim množicam klicateljev.
Celoten program dejansko uporabi protected; natančno pričakovani stdout je 5.
Primeri
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; }
Rezultat
5
Celoten program dejansko uporabi `protected`; natančno pričakovani stdout je `5`.