KO CSharp Keyword partial member - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋ถ๋ถ ๋ฉค๋ฒ์๋ ๋ถ๋ถ ์ ํ ๋ด์ ๋ณ๋์ ์ ์ธ๊ณผ ๊ตฌํ์ด ์์ต๋๋ค. ์ง์ ๋ ๊ณต์ฉ ๋ฉ์๋ ๋ฐ ์์ฑ์ ๋ํ ๊ตฌํ์ ํ์์ ๋๋ค. ๊ทธ๋ ์ ์๋ช ์ด ๊ด๊ณ ์ ์ผ์นํด์ผ ํฉ๋๋ค. ๋ถ๋ถ ์์ฑ์ C# 13๋ถํฐ ์ง์๋ฉ๋๋ค. ํ๋ก์ ํธ๋ ๋ชจ๋ ๋ถ๋ถ์ ํจ๊ป ์ปดํ์ผํฉ๋๋ค.
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
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; }๊ฒฐ๊ณผ:
7
public partial string Format(string name, int count);
public partial string Name { get; set; }ํ์ผ Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>ํ์ผ Program.cs:
using System;
internal static class Program
{
public static void Main()
{
var formatter = new Formatter();
Console.WriteLine(formatter.Format("Bandages", 15));
}
}ํ์ผ Formatter.Contract.cs:
public partial class Formatter
{
public partial string Format(string name, int count);
}ํ์ผ Formatter.Implementation.cs:
public partial class Formatter
{
public partial string Format(string name, int count) => $"{name}: {count}";
}๊ฒฐ๊ณผ:
Bandages: 15
ํ์ผ Example.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>14.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>ํ์ผ Program.cs:
using System;
internal static class Program
{
public static void Main()
{
var settings = new Settings { Name = " Traveller " };
Console.WriteLine($"[{settings.Name}]");
}
}ํ์ผ Settings.Contract.cs:
public partial class Settings
{
public partial string Name { get; set; }
}ํ์ผ Settings.Implementation.cs:
public partial class Settings
{
private string name = "";
public partial string Name
{
get => name;
set => name = value.Trim();
}
}๊ฒฐ๊ณผ:
[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(); } }๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.