KO CSharp Inheritance Interfaces - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
์์, ์ธํฐํ์ด์ค ๋ฐ ๋คํ์ฑ
ํด๋์ค์๋ ํ๋์ ๊ธฐ๋ณธ ํด๋์ค๊ฐ ์์ผ๋ฉฐ ์ฌ๋ฌ ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ ์ ์์ต๋๋ค. virtual๋ ์ฌ์ ์๋ฅผ ํ์ฉํ๊ณ , override๋ ์ด๋ฅผ ๊ตฌํํ๊ณ , abstract๋ ์์์ธ์ ๊ตฌํ์ ์๊ตฌํ๊ณ , sealed๋ ์์์ ์ ํํฉ๋๋ค. base๋ ๊ธฐ๋ณธ ๊ตฌํ์ ๋ํ๋
๋๋ค. new๋ ๋ฉค๋ฒ๋ฅผ ์จ๊ธฐ๊ณ override๋ฅผ ๋์ฒดํ์ง ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
ILabel item = new Item();
System.Console.WriteLine(item.Label);
interface ILabel { string Label { get; } }
class Item : ILabel { public string Label => "Ore"; }
๊ฒฐ๊ณผ:
Ore
interface IDescription
{
string Describe();
}
abstract class Job : IDescription
{
public abstract string Describe();
}
sealed class GatherJob : Job
{
public override string Describe() => "Gathering job";
}
IDescription job = new GatherJob();
UO.Print(job.Describe());
class NamedJob
{
public string Name { get; }
public NamedJob(string name) => Name = name;
public virtual string Report() => Name;
}
sealed class TimedJob : NamedJob
{
public TimedJob(string name) : base(name) { }
public override string Report() => base.Report() + " โ timed";
}
UO.Print(new TimedJob("Search").Report());
์ธํฐํ์ด์ค๋ ์์ฑ๋ ๊ฒ์ ์์ ์ด ์๋ ๊ณ์ฝ์ ์ค๋ช ํฉ๋๋ค. ์ธํฐํ์ด์ค๋ฅผ ๋ช ์์ ์ผ๋ก ๊ตฌํํ๋ฉด ๋์ผํ ์ด๋ฆ์ ๋ฉค๋ฒ๋ฅผ ๊ตฌ๋ถํ ์ ์์ต๋๋ค. ์ต์ C#๋ ์ ์ ํ ์ผ๋ฐ ๊ณ์ฝ์์ ๊ธฐ๋ณธ ๊ตฌํ๊ณผ ์ธํฐํ์ด์ค์ ์ ์ ์ถ์ ๋ฉค๋ฒ๋ฅผ ์ง์ํฉ๋๋ค.
๊ณต์ ๋ฌธ์: ์์, ์ธํฐํ์ด์ค ๋ฐ ๋คํ์ฑ - Microsoft Learn.