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

CKTIS / C#

partial: praktická reference

partial: praktická reference: partial při stejné kompilaci sloučí deklarace i v jediném souboru: typy a metody, od C# 13 také properties a indexery a od C# 14 instanční konstruktory a eventy.

Verze: C# language; verified against C# 14 reference

Syntaxe

partial /* grammar-specific form */

partial při stejné kompilaci sloučí deklarace i v jediném souboru: typy a metody, od C# 13 také properties a indexery a od C# 14 instanční konstruktory a eventy.

Použijte pro generovaný kód a ruční rozšíření bez úpravy generátoru.

Všechny části se musí shodovat v druhu, generic parameters a přístupnosti.

Nevytváří více runtime typů; konfliktní členy jsou chyby kompilace.

Úplný program skutečně používá partial; 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 Split().Read());
partial class Split { public int Read() => 4; } partial class Split { }

Výsledek

4

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

Zdroje