Repository navigation
EN CSharp Keyword partial member
Codex edited this page Oct 11, 2026
·
2 revisions
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Separates a member declaration from its implementation within a partial type. Public partial methods and partial properties require a matching implementation. Partial properties are supported from C# 13; the project compiles all parts together.
Save this example separately as Example.cs. Run it independently of the other examples on this page.
Example.cs:
// PROJECT-EXAMPLE
System.Console.WriteLine(new Item().Read());
partial class Item { public partial int Read(); }
partial class Item { public partial int Read() => 7; }Result:
7
public partial string Format(string name, int count);
public partial string Name { get; set; }File Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>File Program.cs:
using System;
internal static class Program
{
public static void Main()
{
var formatter = new Formatter();
Console.WriteLine(formatter.Format("Bandages", 15));
}
}File Formatter.Contract.cs:
public partial class Formatter
{
public partial string Format(string name, int count);
}File Formatter.Implementation.cs:
public partial class Formatter
{
public partial string Format(string name, int count) => $"{name}: {count}";
}Result:
Bandages: 15
File Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>File Program.cs:
using System;
internal static class Program
{
public static void Main()
{
var settings = new Settings { Name = " Traveller " };
Console.WriteLine($"[{settings.Name}]");
}
}File Settings.Contract.cs:
public partial class Settings
{
public partial string Name { get; set; }
}File Settings.Implementation.cs:
public partial class Settings
{
private string name = "";
public partial string Name
{
get => name;
set => name = value.Trim();
}
}Result:
[Traveller]
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)
{
Counter value = new(5);
Console.WriteLine(value.Value);
}
}
public partial class Counter { public int Value { get; } public partial Counter(int value); }
public partial class Counter { public partial Counter(int value) { Value = value; } }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)
{
Signal value = new();
value.Fired += () => Console.WriteLine("Fired");
value.Fire();
}
}
public partial class Signal { public partial event Action Fired; }
public partial class Signal { private Action? handlers; public partial event Action Fired { add { handlers += value; } remove { handlers -= value; } } public void Fire() { handlers?.Invoke(); } }Official source: Microsoft Learn.
ClassicUO — Bad Newbie & C# Scripts IDE