CKTIS / C#
abstract: praktická referencia
abstract: praktická referencia: abstract označuje neúplný typ alebo člen vyžadujúci implementáciu v odvodenej triede.
Verzia: C# language and .NET 10 reference runtime
Syntax
abstract /* grammar-specific form */abstract označuje neúplný typ alebo člen vyžadujúci implementáciu v odvodenej triede.
Použite na spoločný kontrakt s čiastočnou implementáciou.
Abstract class nemožno vytvoriť; abstract member je virtuálny a nemá telo.
Concrete class musí implementovať všetky abstract members.
Úplný program skutočne používa abstract; presne očakávaný stdout je 4.
Prí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 Concrete().Value);
abstract class Base { public abstract int Value { get; } }
sealed class Concrete : Base { public override int Value => 4; }
Výsledok
4
Úplný program skutočne používa `abstract`; presne očakávaný stdout je `4`.