CKTIS / C#
abstract: odniesienie praktyczne
abstract: odniesienie praktyczne: abstract oznacza niekompletny typ lub składową wymagającą implementacji w klasie pochodnej.
Wersja: C# language and .NET 10 reference runtime
Składnia
abstract /* grammar-specific form */abstract oznacza niekompletny typ lub składową wymagającą implementacji w klasie pochodnej.
Stosuj do wspólnego kontraktu z częściową implementacją.
Nie można utworzyć instancji abstract class; abstract member jest wirtualny bez ciała.
Klasa concrete musi zaimplementować wszystkie abstract members.
Kompletny program rzeczywiście używa abstract; oczekiwany stdout to dokładnie 4.
Przykłady
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 Concrete().Value);
abstract class Base { public abstract int Value { get; } }
sealed class Concrete : Base { public override int Value => 4; }
Wynik
4
Kompletny program rzeczywiście używa `abstract`; oczekiwany stdout to dokładnie `4`.