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 ํ•™์Šต.