KO CSharp Keyword partial type - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: partial์€ ๋ถ€๋ถ„ ์œ ํ˜•์ž…๋‹ˆ๋‹ค.

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

๋ถ€๋ถ„์€ ์ปดํŒŒ์ผ ํƒ€์ž„์— ๋™์ผํ•œ ์œ ํ˜•์˜ ์—ฌ๋Ÿฌ ์„ ์–ธ์„ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค. ๋ถ€ํ’ˆ์€ ๋™์ผํ•œ ์–ด์…ˆ๋ธ”๋ฆฌ ๋ฐ ๋„ค์ž„์ŠคํŽ˜์ด์Šค์— ์†ํ•ด์•ผ ํ•˜๋ฉฐ ์ผ๊ด€๋œ ์œ ํ˜• ์ด๋ฆ„์„ ๊ฐ€์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์†Œ์Šค ํŒŒ์ผ ๊ฐ„์˜ ๋ฐ์ดํ„ฐ์™€ ๋™์ž‘์„ ๋ถ„๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์€ ๋ช‡ ๊ฐ€์ง€ ๋ณ„๊ฐœ์˜ ์œ ํ˜•์ด ์•„๋‹™๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
System.Console.WriteLine(new Item().Name);
partial class Item { public string Name => GetName(); }
partial class Item { private string GetName() => "Ore"; }

๊ฒฐ๊ณผ:

Ore

ํ†ต์‚ฌ๋ก 

public partial class Label { }
public partial struct Rectangle { }

๋ฐ์ดํ„ฐ์™€ ์„œ์‹์ด ๋‹ค๋ฅธ ํŒŒ์ผ์— ์žˆ๋Š” ํด๋ž˜์Šค

ํŒŒ์ผ 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 label = new Label { Name = "Sensor", Number = 12 };
        Console.WriteLine(label.Format());
    }
}

ํŒŒ์ผ Label.Data.cs:

public partial class Label
{
    public string Name { get; init; } = "";
    public int Number { get; init; }
}

ํŒŒ์ผ Label.Display.cs:

public partial class Label
{
    public string Format() => $"{Name} #{Number}";
}

๊ฒฐ๊ณผ:

Sensor #12

์น˜์ˆ˜ ๋ฐ ๋ฉด์  ๊ณ„์‚ฐ์ด ๊ฐ€๋Šฅํ•œ ๋ถ€๋ถ„ ๊ตฌ์กฐ

ํŒŒ์ผ 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 size = new Rectangle { Width = 8, Height = 6 };
        Console.WriteLine(size.Area);
    }
}

ํŒŒ์ผ Rectangle.Size.cs:

public partial struct Rectangle
{
    public int Width { get; init; }
    public int Height { get; init; }
}

ํŒŒ์ผ Rectangle.Area.cs:

public partial struct Rectangle
{
    public int Area => Width * Height;
}

๊ฒฐ๊ณผ:

48

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ