KO CSharp Keyword default - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki
ะฃะบัะฐัะฝััะบะฐ ยท ะ ัััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซไธญๆ ยท ๆฅๆฌ่ช ยท ํ๊ตญ์ด
C#: default
ํธ๋๋ถ C# ยท ์ค์ฉ ๊ฐ์ด๋
default๋ ํ์์ ๊ธฐ๋ณธ๊ฐ์ ๋ง๋ค๊ฑฐ๋ switch์ ๊ธฐ๋ณธ ๋ถ๊ธฐ๋ฅผ ์ง์ ํฉ๋๋ค. where T : default ์ ์ฝ ์กฐ๊ฑด์ ์ ๋ค๋ฆญ ๋ฉ์๋ ์ฌ์ ์ ๋๋ ๋ช
์์ ์ธํฐํ์ด์ค ๊ตฌํ์ ์ฌ์ฉํ๋ฉฐ ์ธํฐํ์ด์ค ๋ฉ์๋ ๋ณธ๋ฌธ์ ์ ์ธํ์ง ์์ต๋๋ค.
๊ฐ๋จํ ์์ (Example.cs)
์ด ์์ ๋ฅผ Example.cs๋ก ๋ฐ๋ก ์ ์ฅํ๊ณ ์ด ํ์ด์ง์ ๋ค๋ฅธ ์์ ์ ๋
๋ฆฝ์ ์ผ๋ก ์คํํ์ธ์.
Example.cs:
// PROJECT-EXAMPLE
int count = default;
string? name = default;
System.Console.WriteLine($"{count}:{name is null}");
๊ฒฐ๊ณผ:
0:True
ํต์ฌ๋ก
default(T) / default / default:
์์ 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)
{
int count = default;
string? name = default(string);
Console.WriteLine($"{count}:{name is null}");
}
}
์ 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)
{
int state = 9;
switch (state) { case 1: Console.WriteLine("Known"); break; default: Console.WriteLine("Unknown"); break; }
}
}
์์ 3
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)
{
IReport report = new Report();
Console.WriteLine(report.Text());
}
}
public interface IReport { string Text() => "default implementation"; }
public class Report : IReport { }
๊ณต์ ์ถ์ฒ: Microsoft ํ์ต.