KO CSharp Keyword extension - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: extension
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
ํ์ฅ ๋ธ๋ก(๊ธฐ์กด ์ ํ์ ๋ํด ๋ฉ์๋, ์์ฑ ๋ฐ ๊ธฐํ ์ง์๋๋ ๋ฉค๋ฒ)์ ์ ์ธํฉ๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
System.Console.WriteLine("ore".Size);
static class TextTools
{
extension(string text) { public int Size => text.Length; }
}
๊ฒฐ๊ณผ:
3
ํต์ฌ๋ก
extension(Type receiver) { public ReturnType Member ... }
C# 14์ ํ์ฅ ๋ธ๋ก ํ์์ด ์ถ๊ฐ๋์์ต๋๋ค. ์ด ๋งค๊ฐ๋ณ์๋ฅผ ์ฌ์ฉํ๋ ํด๋์ ํ์ฅ ๋ฐฉ๋ฒ๋ ์ฌ์ ํ ์ ํจํฉ๋๋ค.
์์ 1: ๊ธฐ๋ณธ ํํ
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)
{
Console.WriteLine("ore".Size);
}
}
public static class TextTools { extension(string text) { public int Size => text.Length; } }
์ 2: ๋ ๋ค๋ฅธ ์ค์ ํ์
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)
{
Console.WriteLine((12).IsEven());
}
}
public static class NumberTools { extension(int value) { public bool IsEven() => value % 2 == 0; } }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.