Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / C#

abstract: praktická reference

abstract: praktická reference: abstract označuje neúplný typ nebo člen vyžadující implementaci v odvozené třídě.

Verze: C# language and .NET 10 reference runtime

Syntaxe

abstract /* grammar-specific form */

abstract označuje neúplný typ nebo člen vyžadující implementaci v odvozené třídě.

Použijte pro společný kontrakt s částečnou implementací.

Abstract class nelze vytvořit; abstract member je virtuální a nemá tělo.

Concrete class musí implementovat všechny abstract members.

Úplný program skutečně používá abstract; přesně očekávaný stdout je 4.

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 Concrete().Value);
abstract class Base { public abstract int Value { get; } }
sealed class Concrete : Base { public override int Value => 4; }

Výsledek

4

Úplný program skutečně používá `abstract`; přesně očekávaný stdout je `4`.

Zdroje