Repository navigation
DE CSharp Keyword abstract
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Handbuch C# · Praktischer Leitfaden
Gibt eine Klasse an, die nicht direkt instanziiert wird, oder ein nicht implementiertes Mitglied, das für einen nicht abstrakten Nachkommen erforderlich ist.
Speichern Sie dieses Beispiel separat als Example.cs. Führen Sie es unabhängig von den anderen Beispielen dieser Seite aus.
Example.cs:
// PROJECT-EXAMPLE
Shape shape = new Square();
System.Console.WriteLine(shape.Area);
abstract class Shape { public abstract int Area { get; } }
class Square : Shape { public override int Area => 4; }Ergebnis:
4
abstract class Base { public abstract void Run(); }using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Entity entity = new Player("Archer");
Console.WriteLine(entity.Describe());
Console.WriteLine(entity.Code);
}
}
public interface ILabel { string Label { get; } }
public abstract class Entity : ILabel
{
private readonly string name;
protected Entity(string name) { this.name = name; }
protected string Name => name;
internal int Code { get; set; } = 7;
public virtual string Label => Name;
public abstract string Describe();
}
public sealed class Player : Entity
{
public Player(string name) : base(name) { }
public override string Label => "Player: " + base.Label;
public override string Describe() => Label;
}using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
public static class Program
{
public static async Task Main(string[] args)
{
Shape shape = new Square(3);
Console.WriteLine(shape.Area);
}
}
public abstract class Shape { public abstract int Area { get; } }
public sealed class Square(int side) : Shape { public override int Area => side * side; }Offizielle Quelle: Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE