KO CSharp Keyword partial type - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋ถ๋ถ์ ์ปดํ์ผ ํ์์ ๋์ผํ ์ ํ์ ์ฌ๋ฌ ์ ์ธ์ ๊ฒฐํฉํฉ๋๋ค. ๋ถํ์ ๋์ผํ ์ด์ ๋ธ๋ฆฌ ๋ฐ ๋ค์์คํ์ด์ค์ ์ํด์ผ ํ๋ฉฐ ์ผ๊ด๋ ์ ํ ์ด๋ฆ์ ๊ฐ์ ธ์ผ ํฉ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์์ค ํ์ผ ๊ฐ์ ๋ฐ์ดํฐ์ ๋์์ ๋ถ๋ฆฌํ ์ ์์ต๋๋ค. ๊ทธ๊ฒ์ ๋ช ๊ฐ์ง ๋ณ๊ฐ์ ์ ํ์ด ์๋๋๋ค.
์ด ์์ ๋ฅผ 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 ํ์ต.