KO CSharp Keyword explicit - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: explicit
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
๋ช ์์ ์บ์คํธ๊ฐ ํ์ํ ์ฌ์ฉ์ ์ง์ ๋ณํ์ ์ ์ธํฉ๋๋ค. ๋ฐ์ดํฐ๊ฐ ์์ค๋๊ฑฐ๋ ๋ก๊ทธ์ธ์ด ํ์ธ๋ ์ ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
Count count = (Count)7;
System.Console.WriteLine(count.Value);
readonly record struct Count(int Value)
{
public static explicit operator Count(int value) => new(value);
}
๊ฒฐ๊ณผ:
7
ํต์ฌ๋ก
public static explicit operator Target(Source value) => ...;
์์ 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)
{
Distance distance = 12;
Console.WriteLine((int)distance);
}
}
public readonly record struct Distance(int Value) { public static implicit operator Distance(int value) => new(value); public static explicit operator int(Distance value) => value.Value; }
์ 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)
{
Label label = "ore";
Console.WriteLine((string)label);
}
}
public readonly record struct Label(string Text) { public static implicit operator Label(string text) => new(text); public static explicit operator string(Label label) => label.Text; }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.