KO CSharp Directive Nullable - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

Null ํ—ˆ์šฉ ์ปจํ…์ŠคํŠธ

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

null ํ—ˆ์šฉ ์ฃผ์„ ๋ฐ null ํ—ˆ์šฉ ๊ฒฝ๊ณ ๋ฅผ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๋Ÿฐํƒ€์ž„ ์‹œ ์ž๋™ null ๊ฒ€์‚ฌ๋ฅผ ์‚ฝ์ž…ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
#nullable enable
string? name = null;
System.Console.WriteLine(name ?? "Unknown");

๊ฒฐ๊ณผ:

Unknown

ํ†ต์‚ฌ๋ก 

#nullable enable / disable / restore / enable warnings / enable annotations

์˜ˆ์‹œ 1

#nullable enable
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)
    {
        string? name = null;
        Console.WriteLine(name ?? "Unknown");
    }
}

์˜ˆ์‹œ 2

#nullable enable annotations
#nullable enable warnings
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)
    {
        string? text = "ore";
        if (text is not null) Console.WriteLine(text.Length);
    }
}

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.