Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

base: practical reference

base: practical reference: base refers to the implementation or constructor of the current object’s base class.

Version: C# language and .NET 10 reference runtime

Syntax

base /* grammar-specific form */

base refers to the implementation or constructor of the current object’s base class.

Use it to extend rather than accidentally skip base behavior.

In a constructor, base must run before the derived body.

It does not expose private members or change virtual dispatch beyond the specified call.

The complete program actually uses base; its exact expected stdout is base.

Examples

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 Derived().Describe());
class Parent { protected virtual string DescribeCore() => "base"; }
sealed class Derived : Parent { public string Describe() => base.DescribeCore(); }

Result

base

The complete program actually uses `base`; its exact expected stdout is `base`.

Sources